2


,我想为我的 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");
    }
}

这行代码创建了一个没有背景图像的全屏窗口。为什么?
我该如何解决?

4

1 回答 1

2

setIconImage是用于窗口图标,而不是用于背景。

例如尝试setBackground。如果你想要一些自定义背景图像,你可能必须重写一些paint(Graphics g)方法,或者设置一些内容窗格/添加一些绘制图像的组件。

于 2011-05-25T12:29:18.333 回答