如何使用Java设置JLabel的颜色? [英] How do I set the color of a JLabel using Java?
本文介绍了如何使用Java设置JLabel的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将在单击 JButton
时创建多个 Jlabel
组件。我知道如何创建标签并在其中设置文本,但是我希望该标签具有颜色。
I will be creating multiple Jlabel
components upon a JButton
click. I know how to create a label and set text inside but I want this label to have a color.
我只知道如何更改具有颜色的标签颜色名称但程序的重要部分是声明标签时,没有下面的代码所示的名称:
I only know how to change the color of a label if it has a name but an important part of my program is when I declare the labels, I don't have names for them as shown in the code below:
newPanel.add(new JLabel("jlabel text"), g);
如何设置标签的颜色?
推荐答案
yourLabel.setForeground(new java.awt.Color(r,g,b);
这篇关于如何使用Java设置JLabel的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文