问题描述
|
大家好
我想为我的JWindow设置背景。我在JWindow中使用了setIconImage方法。但它不起作用
怎么知道问题出在哪里?
public MainMenu() throws Exception {
try {
bg = ImageIO.read(new File(\"pics\" + File.separator
+ \"mainMenuBackground.jpg\"));
content = new JWindow(this);
content.setIconImage(bg);
gs.setFullScreenWindow(content);
content.repaint();
this.setDefaultCloSEOperation(EXIT_ON_CLOSE);
this.repaint();
} catch (Exception e) {
throw new Exception(\"Some files are unavailable\");
}
}
此行代码将创建一个没有背景图像的全屏窗口。为什么?
我该如何解决?
解决方法
setIconImage
用于窗口图标,而不用于背景。
尝试例如setBackground
。如果需要一些自定义背景图像,则可能必须重写某些paint(Graphics g)
方法,或者设置一些内容窗格/添加一些绘制图像的组件。