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

JComboBox

 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a Jcombobox with 9 options to choose from. When a selection is made an event is fired, things happen, and I want to change the text that is displayed inside the combobox. Is there an easy way to do this?
The closest I could come was to totally replace the comboboxmodel that the combobox was using. This in turn reset the selected index and fired an event that I didn't want. Is there a way to turn off events for the combobox? Component(a grandparent of JComboBox) provides a disableEvent(long eventsToDisable) method, but I can't figure out what form the eventsToDisable parameter should take. I haven't seen anything about it in the docs.
Is this the only way to change that text? Is there somewhere I can find out about the eventsToDisable parameter?
Thanks,
Chris
 
Trailboss
Posts: 23780
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this thread to the Swing / AWT forum ...
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the removeItem(object) removeItemAt(int) and removeAllItems() to clear the comboBox. Then use the additem(object) to replace the items. If you want to not invoke any events during this process, simply stop listening for the event.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if this will be of help, but the function .setSelectedItem(String str) will change the text in the ComboBox for you and you can simple remove the listener associated with the ComboBox!
 
reply
    Bookmark Topic Watch Topic
  • New Topic