[英]Frame.getContentPane().setBackground(Color.black) doesn't
I've followed the advice of countless other tutorials for changing the background color of a JFrame, but I haven't any luck. 我遵循了无数其他教程的建议来更改JFrame的背景颜色,但是我没有任何运气。 Here's my code for initializing and creating a frame 这是我用于初始化和创建框架的代码
package frameTests;
import javax.swing.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Foo extends JPanel {
public static void frameInit(Foo foobar){
// window initialization
JFrame frame = new JFrame("Spaceship Defenders!");
frame.add(foobar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.black);
frame.setSize(500,500);
frame.setVisible(true);
frame.setLocationRelativeTo(null);// center frame in screen.
}
public static void main(String[] args) throws InterruptedException{
Foo bar = new Foo();
frameInit(bar);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.