Results 1 to 2 of 2
  1. #1
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    5

    Default 2 Items returned on itemStateChanged() Test???

    Why do I get 2 returned items on itemStateChanged() test?

    Java Code:
            drop = new JComboBox(fileName);
    
            drop.addItemListener(new ItemListener() {
    
                public void itemStateChanged(ItemEvent event) {
    
                    System.out.println(ItemEvent.SELECTED);
                }
            });

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by AcousticBruce View Post
    Why do I get 2 returned items on itemStateChanged() test?

    Java Code:
            drop = new JComboBox(fileName);
    
            drop.addItemListener(new ItemListener() {
    
                public void itemStateChanged(ItemEvent event) {
    
                    System.out.println(ItemEvent.SELECTED);
                }
            });
    A JComboBox uses a single selection model, so when you select an item (which causes an event to be fired) also de-selects another item (which also fires an event). In your event listener you can check whether or not the item is selected.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. SplashScreen.getSplashScreen() returned null
    By kmm1977 in forum AWT / Swing
    Replies: 4
    Last Post: 06-21-2010, 11:04 AM
  2. SplashScreen.getSplashScreen() returned null
    By ibrahimyoussof in forum AWT / Swing
    Replies: 2
    Last Post: 04-17-2010, 02:51 PM
  3. Cant we have two values returned from a method in a class
    By jaiminparikh in forum Advanced Java
    Replies: 7
    Last Post: 03-21-2009, 04:20 AM
  4. Returned type changes if class is extended. How?
    By Gelembjuk in forum New To Java
    Replies: 10
    Last Post: 10-31-2008, 12:18 PM
  5. Replies: 0
    Last Post: 04-05-2008, 12:38 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
  •