File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jComboBox

 
Christopher Alain Jones
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well the combobox is full of HashMap Items.
[ September 28, 2004: Message edited by: Christopher Alain Jones ]
 
Jez Nicholson
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic