简体   繁体   中英

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);                              
} 
}

Basically, there are these four ways:

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));

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