This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes jComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jComboBox" Watch "jComboBox" New topic
Author

jComboBox

Christopher Alain Jones
Greenhorn

Joined: Sep 08, 2004
Posts: 6
ok, i just dunno how
i dont want to select the item like this

String Combo = (String) jComboBox.getSelectedItem();

i just want the actual textline that you can see in the JComboBox, not the item that is behind that.
something like

String Combo = (String) jComboBox.getSelectedText();

how?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Depends on the item in the JComboBox. You can load Strings into the JComboBox and keep an array or Map to index into to get the Object for the selection. Then the String is the selected item (which is what you want, I think). Another option is to make a small DataStore class that stores the Objects and returns a String for each one (like a toString method) that can be loaded into the JComboBox.

The first option is pretty easy. If you use Strings in the JComboBox you can keep an array of (the corresponding) Objects inside the ActionListener class that is registered on the JComboBox and use the selectedIndex from the JComboBox to index into the array.
Christopher Alain Jones
Greenhorn

Joined: Sep 08, 2004
Posts: 6
well the combobox is full of HashMap Items.
[ September 28, 2004: Message edited by: Christopher Alain Jones ]
Jez Nicholson
Ranch Hand

Joined: Oct 01, 2002
Posts: 39
If you haven't applied a renderer then the combo box will display the toString() value of the objects by default.

String displayed = jComboBox.getSelectedItem().toString();
Christopher Alain Jones
Greenhorn

Joined: Sep 08, 2004
Posts: 6
that seems to have worked , cheers

for future referance what is a renderer? and what difference does that make?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jComboBox
 
Similar Threads
ComboBox ItemListener calling twice..
How to connect multiple combo boxes?
check if JcomboBox is contain string
why? this piece of code is not working
JComboBox problem - pls help