Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JComboBox Item Selection Problem

Posted on 2007-12-05
11
Medium Priority
?
1,174 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
  • 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 225 total points
ID: 20415972
Changing the listener type won't help you
0
 
LVL 37

Accepted Solution

by:
zzynx earned 450 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 75 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

927 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