Reputation: 21
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
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
Reputation: 109813
Basically, there are these four ways:
nicer than setBackground
, JToggleButton#setSelectedIcon
, maybe this example
or put them together setBackground
&& setSelectedIcon
best of all is to use Custom Look and Feel, some of them implment this features by default
Upvotes: 3