how to add background color in jframe
package Exaple;
import java.awt.Color;
import javax.swing.JFrame;
public class Window {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
frame.setTitle("Expaple");
frame.setBackground(Color.BLUE);
}
}
4.25
4
setBackground(Color.red);
Thank you!
4
0
4
5
import java.awt.Color; //to be imported
JFrame frame = new JFrame("Figure");
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.getContentPane().setBackground(new Color(0,0,0)); //setting the background color
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
Thank you!
5
0
Are there any code examples left?
New code examples in category Java