设置JWindow背景图像
问题描述:
嘿,所有
我想为我的JWindow设置背景。我在JWindow中使用了setIconImage方法。但它不起作用设置JWindow背景图像
怎么知道问题是什么?
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)
方法,或者设置一些内容窗格/添加一些绘制图片的组件。
+0
哎呀!对不起。我只是认为它必须奏效。我有同样的想法,但很难做到。它有没有像setBackGroundImage()? – 2011-05-25 12:36:19
你为什么认为setIconImage会设置窗口的背景图像?从描述中看,更像是Windows任务栏中显示的图标或其他操作系统中的等效项。你可能需要在paintComponent()方法或类似的东西上绘制图像。 – PhiLho 2011-05-25 12:33:02
[java swing background image]可能的重复(http://*.com/questions/2227423/java-swing-background-image) – finnw 2011-05-25 12:48:48