简体   繁体   中英

How to set font color of a label in Java under RGB format?

How do I do something similar.

lblPlay." set font color under RGB format "

I use Swing framework.

Thanks.

If you try to change the color of a JLabel inside of swing you can just go with

import java.awt.Color;

and then use it like

yourLabel.setForeground(Color.black) //For example black.

or construct the color with

yourLabel.setForeground(new Color(0, 0, 0)) //Provide the r g b values

But if you want a more detailed answer you should provide a minimal example with compilable code or atleast describe where exactly the error happens.

Try to use:

JLabel title = new JLabel("Give me color", JLabel.CENTER);
Color myCustomColor = new Color(100,50,2);
title.setForeground(myCustomColor);

If you're using JavaFX (which you should ;)), use either:

label.setTextFill(Color.rgb(red, green, blue));

where red , green and blue are integers. Or use:

label.setTextFill(Color.web("rrggbb"));

where "rrggbb" is the typical hexademical RGB representation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM