Results 1 to 5 of 5
  1. #1
    harsha is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Don't add an ActionListener. Add an ItemListener instead. Read all about it in the API specs for those methods.

  3. #3
    harsha is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default Re:

    I used only ItemListener , but still itemStateChanged() is triggered even while adding item to the JcomboBox.


    Regards,
    Harsha

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Post your code then. The smallest (compilable and runnable) part that shows the problem.

  5. #5
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    304
    Rep Power
    6

    Default

    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

  1. Event handling... help?
    By kevzspeare in forum New To Java
    Replies: 2
    Last Post: 04-04-2009, 08:46 PM
  2. Event handling in JSF
    By java08 in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 03-24-2009, 06:42 AM
  3. rmi and event handling
    By darkhorse in forum Advanced Java
    Replies: 0
    Last Post: 03-15-2009, 08:20 AM
  4. SWT Event Handling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-30-2007, 12:21 PM
  5. Event Handling
    By luisarca in forum Sun Java Wireless Toolkit
    Replies: 5
    Last Post: 05-07-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •