[英]How to Change the Colour of a JLabel and JButton
如何更改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.