просто мое любопытство, этот код работает на WinXP/Win2003
и Win7/Win2008
различных JRE6_XX_XXX
, не могли бы вы оставить там свой обходной путь для JComboBox
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
public class TestPropListener {
private static final Color TRUE_COLOR = new Color(180, 200, 255);
protected static final Color FALSE_COLOR = new Color(255, 100, 100);
private static void createAndShowUI() {
final MyBean panel = new MyBean();
panel.setTitle(true);
//panel.setPreferredSize(new Dimension(400, 400));
panel.setBackground(TRUE_COLOR);
panel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
panel.setTitle(!panel.getTitle());
}
});
panel.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(MyBean.TITLE_PROP_NAME)) {
panel.setBackground(panel.getTitle() ? TRUE_COLOR : FALSE_COLOR);
}
}
});
JFrame frame = new JFrame("Test Property Listener");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,300);
//frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowUI();
}
});
}
private TestPropListener() {
}
}
class MyBean extends JPanel {
public final static String TITLE_PROP_NAME = "title";
private static final long serialVersionUID = 1L;
private boolean title;
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public boolean getTitle() {
return this.title;
}
public void setTitle(boolean title) {
boolean old = this.title;
this.title = title;
this.pcs.firePropertyChange(TITLE_PROP_NAME, old, title);
}
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
this.pcs.addPropertyChangeListener(listener);
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
this.pcs.removePropertyChangeListener(listener);
}
}