Details
-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.1
-
None
-
sparc
-
solaris_2.5.1
Description
The ItemListener method itemStateChanged is not invoked when the state is changed via method calls. The listener is only notified when the user changes state via user gestures. The enclosed code will print out events when list items are selected by the mouse, but not when the "Next" button changes which item is selected.
import java.awt.*;
import java.awt.event.*;
public class t extends java.applet.Applet
implements ItemListener, ActionListener
{
private List list;
private Button next = new Button("Next");
public void init() {
list = new List();
for (int i = 0; i < 3; i++)
list.add(Integer.toString(i));
list.addItemListener(this);
next.addActionListener(this);
add(list);
add(next);
}
public void itemStateChanged(ItemEvent evt) {
System.out.println("evt = " + evt);
}
public void actionPerformed(ActionEvent e) {
System.out.println("next");
int i = list.getSelectedIndex();
++i;
i %= list.getItemCount();
list.select(i);
}
}
import java.awt.*;
import java.awt.event.*;
public class t extends java.applet.Applet
implements ItemListener, ActionListener
{
private List list;
private Button next = new Button("Next");
public void init() {
list = new List();
for (int i = 0; i < 3; i++)
list.add(Integer.toString(i));
list.addItemListener(this);
next.addActionListener(this);
add(list);
add(next);
}
public void itemStateChanged(ItemEvent evt) {
System.out.println("evt = " + evt);
}
public void actionPerformed(ActionEvent e) {
System.out.println("next");
int i = list.getSelectedIndex();
++i;
i %= list.getItemCount();
list.select(i);
}
}
Attachments
Issue Links
- duplicates
-
JDK-4034837 Checkbox.setState() does not notify listeners
-
- Closed
-