JPanel多个背景图显示。怎么办?
"public class LabelTest { public static void main(String[] args) { JFrame frame = new JFrame(); final Color[] colors = new Color[]{Color。 RED, Color。GREEN}; JComboBox comboBox = new javax。swing。JComboBox(); final JLabel label = new JLabel(" "); comboBox。 setModel(new javax。swing。DefaultComboBoxM...全部
"public class LabelTest { public static void main(String[] args) { JFrame frame = new JFrame(); final Color[] colors = new Color[]{Color。
RED, Color。GREEN}; JComboBox comboBox = new javax。swing。JComboBox(); final JLabel label = new JLabel(" "); comboBox。
setModel(new javax。swing。DefaultComboBoxModel(new String[]{"2009。01。01", "2009。01。02"})); frame。
getContentPane()。add(comboBox, BorderLayout。NORTH); frame。getContentPane()。add(label, BorderLayout。
CENTER); frame。setDefaultCloseOperation(3); comboBox。addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { label。
setIcon(createIcon(colors[(int) (Math。random() * 2)])); } }); frame。setVisible(true); } static Icon createIcon(Color color) { BufferedImage image = new BufferedImage(20, 20, BufferedImage。
TYPE_INT_BGR); Graphics2D g = image。createGraphics(); g。setColor(color); g。fill(new Rectangle(0, 0, 20, 20)); return new ImageIcon(image); }}看看这个把"。
收起