• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

jComboBox

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that seems to have worked , cheers

for future referance what is a renderer? and what difference does that make?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic