设置 JWindow 背景图像
大家好
我想为我的 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");
}
}
这行代码创建了一个没有背景图像的全屏窗口。为什么?
我该如何修复它?
Hey All
I want to set a Background for my JWindow. I used setIconImage method in JWindow. but it's not working
How knows what the problem is?
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");
}
}
This lines of code makes a Full-screen window with no background image. why?
How can i fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setIconImage
用于窗口图标,而不是背景。尝试例如
setBackground
。如果您想要一些自定义背景图像,您可能必须重写一些paint(Graphics g)
方法,或者设置一些内容窗格/添加一些绘制图像的组件。The
setIconImage
is for the window icon, not for the background.Try for instance
setBackground
. If you want some custom background image, you probably have to either override somepaint(Graphics g)
method, or set some content pane / add some component that paints the image.