Java JButton set background color

Description

Java JButton set background color

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {
    super("JButton");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());

    //from   www  .j av  a2  s . c o m
    JButton bn = new JButton("Close");
    bn.setBackground(Color.DARK_GRAY);

    getContentPane().add(bn);
  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related