Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I change the JComboBox items when a mouse click event is triggered?  RSS feed

 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have several JComboBox in an UI. Each of them contains about 3 thousand String. I want to load the data only when user clicks it. Could someone tell me how to detect a mouse click on the JCombobox(only the button area)? Thanks in advance. I am thinking about use a JTextField + JButton + JPopupMenu to do it. If someone has done this before, I would really appreciate that you can share some code with me. Thanks again.
Renee
 
Desiree Morriseau
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would handle this by adding an eventListener to the comboBox and then within the actionPerformed put code that sets the comboBox itemList to the data. YOu could also try to add the data to an array then to the comboBox itemList.
I hope this helps or at least points you in the right direction!! Des
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Desiree,
Thank you for your reply.
I can add a TreeExpansionListener to my JTree to get the current data in the database. But I could find same listener for my JComboBox. My problem is that I could detect the JComboBox Popup event because I couldn't detect when user clicks on the button area of the JComboBox. Now I am using JTextField + JButton + JDialog to do it. It seems working well...
Thanks again for your reply and you have a nice day!
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry. I mean I couldn't find the same eventListener becauseI couldn't detect the mouseEvent.
Renee
 
Wahid Sadik
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may try with ItemListener... i've done so...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!