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

    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
    13,361
    Blog Entries
    7
    Rep Power
    20

    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
    cenosillicaphobia: the fear for an empty beer glass

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, 03: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, 11:18 AM
  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
  •