Solved

JComboBox Item Selection Problem

Posted on 2007-12-05
11
1,167 Views
Last Modified: 2013-12-29
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.
0
Comment
Question by:prain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 20414797
0
 

Author Comment

by:prain
ID: 20414899
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 20415065
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 20415448
you'll need to use a MouseListener
(also try an ActionListener, it may get fired as well)
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 75 total points
ID: 20415972
Changing the listener type won't help you
0
 
LVL 37

Accepted Solution

by:
zzynx earned 150 total points
ID: 20417927
>> 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
 
LVL 92

Assisted Solution

by:objects
objects earned 25 total points
ID: 20417998
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 20418144
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
 

Author Comment

by:prain
ID: 20449317
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
 
LVL 37

Expert Comment

by:zzynx
ID: 20463040
Thanks 4 axxepting
0
 

Author Comment

by:prain
ID: 20464017
Good work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
ejb wildfly example 2 113
java example issue 5 67
Eclipse Java import and method not resolved 4 137
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question