View RSS Feed

Java Swing

How to Write an Item Listener

Rate this Entry
by , 04-26-2012 at 09:32 PM (907 Views)
Components fire the item events which are involved in implementation of the interface ItemSelectable. ItemSelectable components usually maintain off and on state for the items. Swing components involved in firing items include certain buttons, for example, check menu items, combo boxes, check boxes and toggle buttons etc.
Code for the item event handling that has been taken by ComponentEventDemo.java.

Java Code:
//where initialization occurs
checkbox.addItemListener(this);
...
public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        label.setVisible(true);
        ...
    } else {
        label.setVisible(false);
    }
}

Submit "How to Write an Item Listener" to Facebook Submit "How to Write an Item Listener" to Digg Submit "How to Write an Item Listener" to del.icio.us Submit "How to Write an Item Listener" to StumbleUpon Submit "How to Write an Item Listener" to Google

Categories
Actions

Comments