1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class ComboVista extends JFrame {
private JComboBox box;
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
UIManager.getDefaults().put( "ComboBox.disabledBackground", Color.RED );
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ComboVista cv = new ComboVista();
cv.setVisible(true);
}
});
}
public ComboVista() {
super();
build();
}
public void build() {
setTitle("Test Combo & Vista");
setSize(250, 70);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(buildContentPane());
}
private JPanel buildContentPane() {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
box = new JComboBox() ;
box.addItem("disabled") ;
box.setEnabled(false) ;
panel.add(box) ;
return panel;
}
} |
Partager