Below code shows how to setBackground for a JButton. import javax.swing.JFrame; import javax.swing.JButton; import java.awt.Color; public...
Below code shows how to setBackground for a JButton.
import javax.swing.JFrame; import javax.swing.JButton; import java.awt.Color; public class SetBackGroundExample extends JFrame{ SetBackGroundExample () { super("JButton Example"); JButton button=new JButton("Click");//create a new button Color c=Color.BLUE;//Create color button.setBackground(c);//setbackground color button.setBounds(10, 10, 100,20);//set button location add(button);//add button setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,400); setVisible(true); } public static void main(String args[]) { new SetBackGroundExample(); } }