Results 1 to 6 of 6
Thread: repopulate ComboBox
- 04-20-2010, 04:11 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
repopulate ComboBox
I want to repopulate a combobox every time when a user selects an item from the combo box. In the addItemListener, itemStateChanged method, I do removeAllItems first, then do addItems. Unfortunately this doesn't work because it got me into an infinite loop.
Can somebody tell me how to do this?
Thanks!
- 04-20-2010, 04:20 PM #2
Remove the listener before you change the contents and add it after you're done.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 04-20-2010, 05:11 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
I initialize all the listeners on the start up of the program in the following way. How do I stop the listener and restart it? Can I stop the listener inside the statechange routine? Thanks!
Java Code:protected void initListeners() { // ComboBox listener filterNamesCombo.addItemListener( new ItemListener() { public void itemStateChanged( ItemEvent event ) { // Determine whether an item is selected if (event.getStateChange() == ItemEvent.SELECTED) { // Stop listener // remove all items from the combo box // repopulate new items // restart listener } } }); // OK button listener // Cancel button listener }
- 04-20-2010, 06:20 PM #4
No, you don't have a reference to the listener. You'd need something like this:
Java Code:public class Clazz { JComboBox filterNamesCombo = new JComboBox(); ItemListener comboListener = null; protected void initListeners() { comboListener = new ItemListener() { public void itemStateChanged( ItemEvent event ) { // Determine whether an item is selected if (event.getStateChange() == ItemEvent.SELECTED) { // Stop listener filterNamesCombo.removeItemListener(comboListener); // remove all items from the combo box // repopulate new items // restart listener filterNamesCombo.addItemListener(comboListener); } } }; // ComboBox listener filterNamesCombo.addItemListener(comboListener); } }Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 04-20-2010, 06:49 PM #5
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
Thank you so much PhHein. It's working nicely. :)
- 04-20-2010, 07:00 PM #6
You're welcome.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Input box with combobox within
By cowboy in forum New To JavaReplies: 4Last Post: 10-23-2009, 02:07 PM -
problem in combobox
By 435.mahesh in forum AWT / SwingReplies: 3Last Post: 05-04-2009, 05:12 AM -
Need Help combobox
By kwink in forum AWT / SwingReplies: 3Last Post: 03-21-2009, 10:05 AM -
want default value in ComboBox from DB!!
By Java.child in forum AWT / SwingReplies: 2Last Post: 10-04-2008, 12:25 AM -
combobox
By chandu.v in forum New To JavaReplies: 2Last Post: 07-02-2008, 08:36 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks