M. Desjardins
M. Desjardins

Reputation: 1044

Full screen exclusive mode and dual-monitor setup

First I should note that my dual monitors are in custom position rather than the default left-to-right.

I was attempting to create a full-screen exclusive mode game, but in testing I noticed that when I used EXIT_ON_CLOSE (and in System.exit), that the monitor setup would be reset to the default left-to-right. But when I used DISPOSE_ON_CLOSE (and for just a dispose()) it would be perfectly normal when returning to my desktop. Is this acceptable practice, or is there something I'm missing?

Relevant part:

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

public class FullScreenTest extends JFrame {

    public FullScreenTest() {
        GraphicsDevice screen = GraphicsEnvironment.
              getLocalGraphicsEnvironment().getDefaultScreenDevice();
        add(new JLabel("Test"));
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        screen.setFullScreenWindow(this);
    }

    public static void main(String[] args) {
        FullScreenTest test = new FullScreenTest();
    }
}

Upvotes: 1

Views: 669

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168825

But when I used DISPOSE_ON_CLOSE (and for just a dispose()) it would be perfectly normal when returning to my desktop

That is good. Stick with it. Many developers use EXIT_ON_CLOSE when it is entirely unnecessary.

If DISPOSE_ON_CLOSE does not work to end the JRE, it means that other GUI elements are still visible, or other non-daemon threads are running. In that case, it would generally be better to explicitly end the other threads, or check they can safely be ended.

Upvotes: 2

mKorbel
mKorbel

Reputation: 109813

Upvotes: 2

Related Questions