2

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?

Pro.Hessam
  • 819
  • 3
  • 11
  • 26
  • Why do you think that setIconImage will set the background image of the window? Looks, from the description, more like the icon displayed in the Windows taskbar or equivalent in other OSes. You might need to paint the image in the paintComponent() method or something, perhaps. – PhiLho May 25 '11 at 12:33
  • possible duplicate of [java swing background image](http://stackoverflow.com/questions/2227423/java-swing-background-image) – finnw May 25 '11 at 12:48

1 Answers1

2

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 some paint(Graphics g) method, or set some content pane / add some component that paints the image.

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • oops! I'm sorry. I just thought it must work. I had the same idea, but it's hard to do. Doesn't it have anything like setBackGroundImage() ??? – Pro.Hessam May 25 '11 at 12:36