如何更改 JLabel 和 JButton 的颜色
How to Change the Colour of a JLabel and JButton
我刚刚使用以下方法更改了框架的背景颜色:
panel1.setBackground(Color.GRAY);
现在,如果更改文本和按钮可能会更好看。我怎样才能让 JLabel
和 JButtons
更亮一点?当它是白色的时候会好很多,因为现在它看起来像这样:
想象一下那个!
How to Change the Colour of a JLabel and JButton
要更改 JLabel 和 JButton 的背景颜色,您可以这样做:
JButton btn = new JButton();
btn.setBackground(Color.WHITE);
JLabel lbl= new JLabel ();
lbl.setBackground(Color.WHITE);
lbl.setOpaque(true); //If opaque property is false, you can't see the color
要更改 JLabel 和 JButton 的文本颜色,您可以这样做:
btn.setForeground(Color.WHITE);
lbl.setForeground(Color.WHITE);
JButton button = new JButton("test");//sample JButton
button.setBackground(Color.WHITE);//Set background color
button.setOpaque(true);//needs to be true in order to show color
JLabel title = new JLabel("I love Whosebug!", JLabel.CENTER);
title.setForeground(Color.white);//simply set color
我刚刚使用以下方法更改了框架的背景颜色:
panel1.setBackground(Color.GRAY);
现在,如果更改文本和按钮可能会更好看。我怎样才能让 JLabel
和 JButtons
更亮一点?当它是白色的时候会好很多,因为现在它看起来像这样:
想象一下那个!
How to Change the Colour of a JLabel and JButton
要更改 JLabel 和 JButton 的背景颜色,您可以这样做:
JButton btn = new JButton();
btn.setBackground(Color.WHITE);
JLabel lbl= new JLabel ();
lbl.setBackground(Color.WHITE);
lbl.setOpaque(true); //If opaque property is false, you can't see the color
要更改 JLabel 和 JButton 的文本颜色,您可以这样做:
btn.setForeground(Color.WHITE);
lbl.setForeground(Color.WHITE);
JButton button = new JButton("test");//sample JButton
button.setBackground(Color.WHITE);//Set background color
button.setOpaque(true);//needs to be true in order to show color
JLabel title = new JLabel("I love Whosebug!", JLabel.CENTER);
title.setForeground(Color.white);//simply set color