gpt4 book ai didi

java - 如何更改 JLabel 和 JButton 的颜色

转载 作者:行者123 更新时间:2023-12-01 10:18:47 26 4
gpt4 key购买 nike

我刚刚使用以下方法更改了框架的背景颜色:

panel1.setBackground(Color.GRAY);

现在,如果更改文本和按钮,可能看起来会更好。如何将 JLabelJButtons 更改得更亮一点?当它是白色的时候会好得多,因为现在它看起来像这样:

Wall game

想象一下!

最佳答案

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);

关于java - 如何更改 JLabel 和 JButton 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35751807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com