Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox Listener problem  RSS feed

 
Markus Schmider
Ranch Hand
Posts: 148
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have three JComboBoxes.
When the user selects an entry in the first JComboBox the entries in the second are set. For this I use an Action extends AbstractAction which is bound to the first JComboBox
I have also bound an Action to the second JComboBox.
Problem: this also fires when the entries on the second JCombox are added which leads to a Nullpointer.

I need a Listener which only reacts to user input, and does not react when the model of the JComboBox is changed.
 
Campbell Ritchie
Sheriff
Posts: 55327
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the Java Tutorials. It suggest an action listener, I think.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the ActionListener of the first combo box the basic code should be:

1) remove the listener from the second combo box
2) update the second combo box
3) restore the listener of the second combo box
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!