簡體   English   中英

如何更改JLabel和JButton的顏色

[英]How to Change the Colour of a JLabel and JButton

我只是使用以下方法更改了框架的背景顏色:

panel1.setBackground(Color.GRAY);

現在,如果更改文本和按鈕,可能會看起來更好。 如何更改JLabelJButtons的亮度呢? 白色時會更好,因為現在看起來像這樣:

牆上游戲

想象一下

如何更改JLabel和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 stackoverflow!", JLabel.CENTER);

title.setForeground(Color.white);//simply set color

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM