This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
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: Telling difference if model update or actual select.  RSS feed

 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again.
I got a problem with the action/itemlistener of a JCombobox.
Is there a way to tell the difference if the model was updated via addElement or an item was selected?
The ActionCommand of both is the same.
Problem is, i update the comboboxmodel via a swingworker so no way to know when it is updating.
Any ideas?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • Remove the listener
  • Update the model
  • Add the listener

  •  
    Manuel Petermann
    Ranch Hand
    Posts: 177
    Hibernate Linux Python
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That is a rather blunt way to do it. I thought that there might be a better way to it.
    But if thats not the case I think i will implement that.
     
    Darryl Burke
    Bartender
    Posts: 5167
    11
    Java Netbeans IDE Opera
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you prefer:
  • Set a boolean flag
  • Update the model
  • Reset the flag


  • In the listener, test the flag
  •  
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!