-1

I've been trying to display an image in fullscreen mode in java with JFrame but I can't get it to work.

When I create a new object of this a white window opens in fullscreen mode but the image does not get displayed:

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class DisplayManager {

    private JFrame jf;

    public DisplayManager() {

        //jframe
        jf = new JFrame();
        jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
        jf.setUndecorated(true);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getDefaultScreenDevice();
        device.setFullScreenWindow(jf);

        jf.add(new JLabel(new ImageIcon("E:/NetBeansProjects/Project/res/Test.png")));

    }

}
Marcus
  • 35
  • 6
  • Does it show up if you don't use fullscreen mode? – Kayaman Oct 16 '17 at 16:06
  • 1
    Possible duplicate of [Displaying an image in Java Swing](https://stackoverflow.com/questions/8333802/displaying-an-image-in-java-swing) – pvg Oct 16 '17 at 16:08
  • If i remove device.setFullScreenWindow(jf); nothing shows up. Edit: When i remove the GraphicsEnvironment stuff and jf.setUndecorated(true); a white window opens. When i resize this window the image shows up :/ – Marcus Oct 16 '17 at 16:10

1 Answers1

0

The default size of a component is (0, 0), so there is nothing to paint unless the layout manager has been invoked to give the component a size and location.

Components need to be added to the frame BEFORE the frame is made visible.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Oh wow. I feel stupid now. I just had to call jf.setVisible(true); after adding the image. Thanks :) – Marcus Oct 16 '17 at 16:17