我的Java图形界面设置的背景颜色怎么不显示啊??程序很简单。。
importjava.awt.Color;importjavax.swing.JFrame;publicclassTryWindow{staticJFrameaWindo...
import java.awt.Color;
import javax.swing.JFrame;
public class TryWindow {
static JFrame aWindow=new JFrame("This is a window Title");
public static void main(String[] args) {
int windowWidth=400;
int windowHeight=150;
aWindow.setBounds(50, 100, windowWidth, windowHeight);
aWindow.setBackground(new Color(99,00,180));
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println(aWindow.getBounds());
aWindow.setVisible(true);
}
} 展开
import javax.swing.JFrame;
public class TryWindow {
static JFrame aWindow=new JFrame("This is a window Title");
public static void main(String[] args) {
int windowWidth=400;
int windowHeight=150;
aWindow.setBounds(50, 100, windowWidth, windowHeight);
aWindow.setBackground(new Color(99,00,180));
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println(aWindow.getBounds());
aWindow.setVisible(true);
}
} 展开
展开全部
你把aWindow.setBackground(new Color(99,00,180));改成下面的就可以了.
aWindow.getContentPane().setBackground(new Color(99,00,180));
aWindow.getContentPane().setBackground(new Color(99,00,180));
追问
为啥我改成aWindow.getContentPane().setBackground(new Color(99,00,180));就有颜色了呢?
谢谢。getContentPane()是个啥玩意?呵呵
追答
getContentPane()
返回此窗体的 contentPane 对象
JFrame不能直接设置背景色的.. 只有先得到contentPane 然后设置颜色.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询