• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

getting text on JComboBox

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To all,
I am having a bit of trouble getting text from a editable JComboBox field. I have checked the earlier posts on this topic and i still seem to have trouble with this.
When the user clicks on a button i would like to get the data stored in a combo box? I populate the fields with data from a selected file. Isnt there an easier way to get data from a box than handling an event?
JComboBox AOnePos = new JComboBox;
AOnePos.setEditable(true);
.
.
.
Thanks.. Andy

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andy,
I have used the selected item from a ComboBox when my ADD button is activated. But you could probably test if the selected item has changed. You would have to initialize it with a known item (like Null) and check if it changed. However I think an event is a better approach.
HTH
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andy,
When your user clicks your button, you have to handle ActionPerformed for the button. You do not need to handle an event for the combo, simply read its text when you handle the button ActionPerformed :

Kate
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Since ur JCombobox is editable, the earlier given approaches may not work.
The best approach is
((JTextField)c.getEditor().getEditorComponent()).getText();
where c is ur JCombobox instance
Regards
Saj
reply
    Bookmark Topic Watch Topic
  • New Topic