Name: el35337 Date: 06/11/98
Create a new JComboBox and a button. Give the
comboBox 3 values and setSelectedItem to one of
the values. Have the button change the selectedItem
of the combobox and the arrow on the combobox will
disappear. It reappears if you click where it should
be. Sample attached.
/*
*/
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.plaf.*;
import com.sun.java.swing.text.*;
/**
*/
public class ComboBug extends JPanel implements java.awt.event.ActionListener {
static JFrame frame;
private JComboBox cb = null;
private JButton button = null;
public ComboBug() {
cb = new JComboBox();
cb.setEditable(true);
cb.addItem("Value 1");
cb.addItem("Value 2");
cb.addItem("Value 3");
cb.setSelectedItem("Value 2");
button = new JButton("Chang Value");
button.addActionListener(this);
add(cb);
add(button);
}
public static void main(String s[]) {
ComboBug panel = new ComboBug();
frame = new JFrame("LifePRO Prime Color Selections");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
frame.getContentPane().add("Center", panel);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try {
cb.setSelectedItem("Value 3");
}
catch (Exception exc) {
System.err.println("catch done on action performed");
}
}
}
(Review ID: 33506)
==================================
====================================
On Win32, creating an editable JComboBox results
a combobox with the arrow failing to paint
properly. Redisplaying (occuding by another
window and bringing it back to the front) repaints
the window properly.
It appears that the arrow appears there very
briefly (a quick flicker) before disappearing.
It's probably getting overwritten by the
JTextField before the textfield gets resized to
make room for the error.
Here's a simple application which demonstrates
the problem:
import java.awt.*;
import com.sun.java.swing.*;
public class Test extends JFrame {
public Test() {
Container c = getContentPane();
setSize(640, 480);
c.setLayout(new FlowLayout());
JComboBox jc;
c.add(jc = new JComboBox());
jc.setEditable(true);
}
public static void main(String args[]) {
new Test().show();
}
}
erik.larsen@Eng 1998-06-17