Marta Azoia
Marta Azoia

Reputation: 25

How to change text color with a button in java

Im working on NetBeans and i want to change the color of my texts and change my images when i click on buttons, the blue button changes to blue, the red to red etc. Im doing:

    EscolherCor.setTextColor(0,0,0);

Is there any code i can use to solve this?

Upvotes: 0

Views: 5707

Answers (1)

Blasanka
Blasanka

Reputation: 22417

There are different ways you can achieve this:

Only to a font:

JLabel EscolherCor= new JLabel ("Color");
EscolherCor.setForeground(Color.red);

Using Hex value:

JLabel EscolherCor= new JLabel ("Color");
Color color = Color.decode("#43B7BA");
EscolherCor.setForeground(color);

Using RGB:

JLabel EscolherCor= new JLabel ("Color");
Color color = new Color(255,0,0);
EscolherCor.setForeground(color);

Using html:

JLabel EscolherCor = new JLabel("<html>label <font color='blue'>blue-color</font></html>");

To the background:

JLabel EscolherCor= new JLabel ("Color");
EscolherCor.setBackground(Color.red);

Upvotes: 1

Related Questions