搜索
首页 电脑/网络 互联网

JPanel多个背景图显示。怎么办?

全部回答

2018-04-30

0 0
    "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); }}看看这个把"。
    。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
互联网
硬件
电脑装机
程序设计
操作系统/系统故障
笔记本电脑
反病毒
百度
软件
互联网
互联网
QQ
网站推荐
上网帮助
举报
举报原因(必选):
取消确定举报