Question

I have this code inside my class MainWindow:

public MainWindow() {
    super("Shouldn't be visible...");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setAlwaysOnTop(true);
    setUndecorated(true);
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    addFocusListener(new FocusLostExiter());
    addKeyListener(new EscListener());

    setContentPane(canvas);

    getContentPane().setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
    pack();
    setResizable(false);
}

public void setFullScreen(boolean b) {
    if(!b) {
        device.setFullScreenWindow(null);
    }
    setVisible(b);
    //System.out.println(device.getFullScreenWindow());
    if(b) {
        device.setFullScreenWindow(this);
    }
}

In Windows 7+Java 6, it works as full screen just fine. I can click anywhere without problems. However, in Windows 8+Java 6, all of the leftmost column of pixels except for about 100 near the top, and a box where the start button should be, are messed up. In the column and the box, my cursor changes to a normal mouse again and the window ignores my clicks. In the start box, clicking brings up the start menu instead of giving my program a click event. This seems to be a problem with Java, cause it works everywhere but W8. Do you know what's wrong/how to fix or get around it?

Was it helpful?

Solution 6

Never answered this properly... It was an issue with the JRE on Windows 8 itself. Now fixed.

OTHER TIPS

I had a similar problem before, the bottom of the window was getting cut off on Windows machines, and adding in these lines fixed the issue:

frame.setLocationByPlatform(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Assuming that your MainWindow class extends JFrame, calling these two methods should do the trick.

public NewFrame(){

    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    this.setSize(Toolkit.getDefaultToolkit().getScreenSize());

    this.setVisible(true);

}

You can easily just place this inside your constructor

 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 setBounds(0,0,screenSize.width, screenSize.height);

Try this out for full screen, usually it is preferred to use half the width and height of the original screen size

Toolkit toolkit = Toolkit.getDefaultToolKit();

Dimension d = toolkit.getScreenSize();

int w = d.width;

int h = d.height;

setSize(w,h);

Well, if your MainWindow class is a JFrame, then you don't have to use getContentPane(). I don't think you need the setFullScreen function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top