IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes JComboBox: Telling difference if model update or actual select. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "JComboBox: Telling difference if model update or actual select." Watch "JComboBox: Telling difference if model update or actual select." New topic
Author

JComboBox: Telling difference if model update or actual select.

Manuel Petermann
Ranch Hand

Joined: Jul 19, 2011
Posts: 88

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?


Please correct my english.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 3221

  • Remove the listener
  • Update the model
  • Add the listener


  • luck, db
    There are no new questions, but there may be new answers.
    Manuel Petermann
    Ranch Hand

    Joined: Jul 19, 2011
    Posts: 88

    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

    Joined: May 03, 2008
    Posts: 3221

    If you prefer:
  • Set a boolean flag
  • Update the model
  • Reset the flag


  • In the listener, test the flag
  •  
     
    subject: JComboBox: Telling difference if model update or actual select.
     
    Threads others viewed
    how to reflect changes of Data in a JComboBox?
    Swing and pattern observer
    jdbc and swing
    How to make JComboBox flash (red color)?
    Onchange JCombobox
    developer file tools