Results 1 to 5 of 5
- 09-18-2009, 07:32 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
Prob with event handling for Jcombox
Hi All,
I using a JComboBox , i perform a task in actionPerformed() , and i want this task to be performed if only there is a change in the selection of JComboBox .
I problem i face is ,actionPerform() gets triggered both when adding items to the JComboBox as well as when item selected is being changed.
Can somebody please tell me how can i make some task perform only if the selection of item is changed but not when when item is being added.
Thanx,
Harsha
- 09-18-2009, 08:34 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't add an ActionListener. Add an ItemListener instead. Read all about it in the API specs for those methods.
- 09-18-2009, 09:51 AM #3
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
Re:
I used only ItemListener , but still itemStateChanged() is triggered even while adding item to the JcomboBox.
Regards,
Harsha
- 09-18-2009, 10:16 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Post your code then. The smallest (compilable and runnable) part that shows the problem.
- 09-18-2009, 03:14 PM #5
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
It sounds like to me you are adding the Listener before you are setting the items in the combo box.
The action event and the itemchangedevent are thrown whenever the selected item changes, and if there is nothing in the box when you add items, it will select the first item added and throw the events.
Similar Threads
-
Event handling... help?
By kevzspeare in forum New To JavaReplies: 2Last Post: 04-04-2009, 08:46 PM -
Event handling in JSF
By java08 in forum JavaServer Faces (JSF)Replies: 0Last Post: 03-24-2009, 06:42 AM -
rmi and event handling
By darkhorse in forum Advanced JavaReplies: 0Last Post: 03-15-2009, 08:20 AM -
SWT Event Handling
By Java Tip in forum Java TipReplies: 0Last Post: 12-30-2007, 12:21 PM -
Event Handling
By luisarca in forum Sun Java Wireless ToolkitReplies: 5Last Post: 05-07-2007, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks