-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
None
-
swing1.0.3
-
generic
-
generic
Using setSelectedIndex() of JComboBox doesn't cause the UI to repaint
the combobox under swing 1.0.2. Is this a bug or was something changed
where now I need to explicitly tell it to update?
Here's a sample application that works under 1.0.1 but not 1.0.2.
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class combotest {
JComboBox combo;
public combotest() {
Object[] items = {"Foo", "Bar", "This", "That", "Bletch", "Gack"};
JFrame frame = new JFrame("ComboBox Test");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
combo = new JComboBox(items);
// Each button click should display the next item in the combo box
JButton button = new JButton("Click Me");
button.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent evt) {
try {
combo.setSelectedIndex(combo.getSelectedIndex() + 1);
} catch(IllegalArgumentException e) {
combo.setSelectedIndex(0);
}
}
});
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(button);
frame.getContentPane().add("South", combo);
frame.pack();
frame.show();
}
public static void main(String[] args) {
new combotest();
}
} // combotest
the combobox under swing 1.0.2. Is this a bug or was something changed
where now I need to explicitly tell it to update?
Here's a sample application that works under 1.0.1 but not 1.0.2.
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class combotest {
JComboBox combo;
public combotest() {
Object[] items = {"Foo", "Bar", "This", "That", "Bletch", "Gack"};
JFrame frame = new JFrame("ComboBox Test");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
combo = new JComboBox(items);
// Each button click should display the next item in the combo box
JButton button = new JButton("Click Me");
button.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent evt) {
try {
combo.setSelectedIndex(combo.getSelectedIndex() + 1);
} catch(IllegalArgumentException e) {
combo.setSelectedIndex(0);
}
}
});
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(button);
frame.getContentPane().add("South", combo);
frame.pack();
frame.show();
}
public static void main(String[] args) {
new combotest();
}
} // combotest