ItemEvent Class
Package: java.awt
An instance of the ItemEvent class is passed to the ItemListener whenever the item selected in a list control (such as a list box or combo box) is changed. You can use this object to determine information about the event such as which item the user selected.
Fields
|
Field |
Description |
|
|
This value is returned by the |
|
|
This value is returned by the |
Methods
|
Method |
Description |
|
|
Returns the item that was selected or deselected |
|
|
Returns the object on which the event occurred |
|
|
Returns either |
You can use the getSource method to determine which component sourced the event when the listener is registered as an event listener with more than one component. For example:
private class MyItemListener
implements ItemListener
{
public void itemStateChanged(ItemEvent e)
{
if (e.getSource() == listBox1)
{
// code to handle listBox1 changed
}
if (e.getSource() == listBox2)
{
// code to handle listBox2 changed
}
}
}
In this example, the private class MyItemListener can be registered with two list boxes (listBox1 and listBox2). The getSource method is used in the itemStateChanged method to determine which list ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access