JComboBox Item Selection Problem

Hello,
I have a JComboBox with items listed. User selects an Item. The Item Event is generated. It is trapped in the ItemStateChanged() listener. Now The Item is HILIGHTED on the display. Now The User Clicks on that Item AGAIN. THERE IS NO ITEM EVENT GENERATED. You must Deselect that item and select it again to regenerate the ItemEvent. This is not good for the user.

We have an application that this happens. How to solve this?. Actually, the way it works is :"The Way" ItemEvent is generated. If an Item is already selected, bu clicking on that same selected item again does not generate an ItemEvent.
prainAsked:
Who is Participating?
 
zzynxConnect With a Mentor Software engineerCommented:
>> Now The User Clicks on that Item AGAIN. THERE IS NO ITEM EVENT GENERATED
>> Actually, the way it works is :"The Way" ItemEvent is generated.
>> If an Item is already selected, bu clicking on that same selected item again does not generate an ItemEvent.
That's how I would expect it to work. (And it does)

When you click on the selected item, why should ItemStateChanged() be triggered again?
The item's state does not change, so...

>> You must Deselect that item and select it again to regenerate the ItemEvent.
Completely logical. This really changes the item's state

>> This is not good for the user.
Why not? What would you want to "do" if the user selects an already selected item?
0
 
prainAuthor Commented:
I am not sure what you explain here...

I even do not get the ItemEvent triggered when clicked in the same selected item for the second time.

public void itemStateChanged(ItemEvent iEvent)
{
  System.out.println("Passed");
}
 
I See the word "Passed" printed on my console when the item is selected for teh first time. Then when I click on the same item, there is no "Passed" printed. That tells me that the ItemEvent is not even generated at the second time.

Thanks
Kumar
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
In that case, it suggests that you event queue is being blocked. Make sure you're not running anything remotely resource/time consuming in the event handler. It should be *started* there, but run in a separate thread
0
 
objectsCommented:
you'll need to use a MouseListener
(also try an ActionListener, it may get fired as well)
0
 
CEHJConnect With a Mentor Commented:
Changing the listener type won't help you
0
 
objectsConnect With a Mentor Commented:
we know thats the way that listener works, which is why you need to use a different type of listener to get the desired behaviour as has already been suggested.

> Why not? What would you want to "do" if the user selects an already selected item?

there can be many reasons.
0
 
CEHJCommented:
Sorry - prain - misread your question. That's how ItemListener is meant to work. If you want it otherwise, then changing the type of listener is essential
0
 
prainAuthor Commented:
OK. Ok. Ok. All right. Thanks all for everyone's opinion. In fact ItemEvent will not be generated when an item (which is already)selected is clicked again. That's because THERE IS NO STATE CHANGE happen. In fact when a new item is selected then the ItemEvent is generated twice (One when leaving the previous one - there is a state change and the other is when the new one get selected - again the item state change happen).

So mine is now working very well aftr I removed the ItemListener from the combobox and added a ActionListener instead.

Well I am going to split the points, so everyone will be happy. All of you have helped me previously with valuable infomation.
0
 
zzynxSoftware engineerCommented:
Thanks 4 axxepting
0
 
prainAuthor Commented:
Good work.
0
All Courses

From novice to tech pro — start learning today.