| 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?
|
 |
 |
|
|
subject: jComboBox
|
|
|