1. Technology
Send to a Friend via Email



Person operating a laptop
Medioimages/Photodisc/Getty Images

The ItemListener interface is used to handle item events triggered by graphical components that implement the ItemSelectable interface (e.g., JComboBox, JCheckBox, JRadioButton, etc..).

It's a simple interface that only requires a class to implement one method:

public interface ItemListener {

    public void itemStateChanged(ItemEvent e);


You can attach an ItemListener event listener as an anonymous inner class to a JComboBox:

//Options for the combo box dialog
String[] choices = {"Monday", "Tuesday"
                ,"Wednesday", "Thursday", "Friday"};
JComboBox weekDays = new JComboBox(choices);
//Attach an ItemListener to weekDays by using
//an anonymous inner class
weekDays.addItemListener(new ItemListener(){
  public void itemStateChanged(ItemEvent e)
     //place the code to execute when the item event

Have a look at How to Handle Item Events and a ItemListener Example Code Program.


# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

  1. About.com
  2. Technology
  3. Java
  4. Java Glossary
  5. I
  6. Definition for the Java Term: ItemListener

©2014 About.com. All rights reserved.