aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes editable JCombobox need help getting text from user Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "editable JCombobox need help getting text from user" Watch "editable JCombobox need help getting text from user" New topic
Author

editable JCombobox need help getting text from user

imran ibrahim
Greenhorn

Joined: May 23, 2005
Posts: 6
Hi i've looked at the tutorials and all over google.. but i just can't seem to get how i can make a combobox, editable.
Then if the user selects from the drop down list i want to grab that in a string... or if a user types something in the field and then presses a button, I want to grab the text.. I guess i'm having trouble understanding the hierarchy of events... really hope someone can help here.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

imrang dude

Welcome to Javaranch. Perhaps you overlooked it but we do have a Naming Policy the prohibits the use of obviously fake names. If you could adjust your display name to meet our guidelines, that would be great.

Thanks.


GenRocket - Experts at Building Test Data
imran ibrahim
Greenhorn

Joined: May 23, 2005
Posts: 6
done... do you er... have any tips for my question ?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Thanks for changing your display name.

Have you been through any of Sun's JComboBox Tutorials? I believe it will answer most if not all your questions. If you get stuck on something specific let us know and we can try and help. If I were to answer your current question(s) I'd just be writing Sun's tutorial all over again.
imran ibrahim
Greenhorn

Joined: May 23, 2005
Posts: 6
yea i read it sooo many times... but when u creat a combobox and make it editable, I can't see what part of the code will get text from the field the user enters, i know the get selectedItem selects from the dropdown.. let's say he types in an ip address and clicks a button called connect... as soon as he doesnt that how do u grap the ip into a string?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

If you doing it with the click of a button

imran ibrahim
Greenhorn

Joined: May 23, 2005
Posts: 6
Yo that works amazing! thank you... btw the captured string can i store in a variable and using on setText for a label some where?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by imran ibrahim:
Yo that works amazing! thank you... btw the captured string can i store in a variable and using on setText for a label some where?


Yep.
imran ibrahim
Greenhorn

Joined: May 23, 2005
Posts: 6
hmm i tried that and when i do it ... i press the connect buttoni get this:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Client.applyLabel(Client.java:243)
at Client$1.actionPerformed(Client.java:59)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
any ideas?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

So can I see the code?
imran ibrahim
Greenhorn

Joined: May 23, 2005
Posts: 6
hey sorry dude... i figured it out. i had no idea that creating a label after a button would cause such problems..damn... seems like i had to create the label first or it would always cause a null pointer error.. damn...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: editable JCombobox need help getting text from user