Results 1 to 3 of 3
  1. #1
    rainman3 is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default differentiate between user selection and "additem" method in combobox

    I'm trying to find a way for a JComboBox
    action listener or item listener to differentiate between
    the user making a selection and the invocation of methods
    such as removeAllItems() and addItem(). As far as I've
    been able to see, the ActionEvents and ItemEvents are
    exactly the same.

    I don't want actionperformed to be called in additem or removeallitems function.
    I want actionperformed to be called when only user change combobox items.
    How can I solve this problem?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    One way (not sure if it's the best, but it works) is to remove all listeners prior to calling removeAllItems or addItem, and then re-add the listeners after these jobs have been complete.

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    The ItemListener should only change if the selection changes, and not when adding/removing items.
    You should be able to work out what triggered an event by looking at the ActionEvent or ItemEvent objects.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Facing issue in printing user like "ab\\cd"
    By psmhelp in forum New To Java
    Replies: 4
    Last Post: 04-27-2009, 01:28 PM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Can't get my "if" statement to read user input
    By daletron3030 in forum New To Java
    Replies: 7
    Last Post: 01-16-2009, 05:24 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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