Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

jComboBox

 
Greenhorn
Posts: 6
  • 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?
 
Ranch Hand
Posts: 1535
  • 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
  • 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 ]
 
Ranch Hand
Posts: 39
  • 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
  • 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?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!