Marian Siska
Marian Siska

Reputation: 21

How to color Jbutton in java

hello guys i have problem coloring those buttons the background allways change color but the other stay in grey color, any way to change that to other color? /sorry for my english/

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Prepinac extends JFrame        
{                          
JToggleButton prepinac1 = new JToggleButton("prepinac");    
 public static void main(String [] args)
{
    Prepinac prepinace = new Prepinac();        
    Container kontainer = prepinace.getContentPane(); 
    kontainer.setLayout(new FlowLayout());   
    kontainer.add(prepinace.prepinac1);           
    kontainer.add(new JButton("tlacidlo"));

    prepinace.setDefaultCloseOperation(EXIT_ON_CLOSE);         
    prepinace.pack();                                           
    prepinace.setVisible(true);                              
} 
}

Upvotes: 2

Views: 529

Answers (2)

Martin Rohwedder
Martin Rohwedder

Reputation: 75

You could try using nimbus L&F, and then set the base color of the layout

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
UIManager.put("base", new java.awt.Color(80,0,0));

Upvotes: 2

mKorbel
mKorbel

Reputation: 109813

Basically, there are these four ways:

Upvotes: 3

Related Questions