如何设置
JFrame
的背景颜色?您可以使用此代码块来设置JFrame的背景颜色。
JFrame frame = new JFrame("Frame BG color");
frame.setLayout(null);
frame.setSize(1000, 650);
frame.getContentPane().setBackground(new Color(5, 65, 90));
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
public nameOfTheClass() {
final Container c = this.getContentPane();
public void actionPerformed(ActionEvent e) {
c.setBackground(Color.white);
}
}
import java.awt.*;
import javax.swing.*;
public class MySimpleLayout extends JFrame {
private Container c;
public MySimpleLayout(String str) {
super(str);
c=getContentPane();
c.setLayout(null);
c.setBackground(Color.WHITE);
}
}
可能最简单的方法是这样的:
super.setBackground(Color.CYAN);
frame.getContentPane().setBackground(Color.PINK);
- ParisaN