davidahines
davidahines

Reputation: 4094

How to set resolution of a Java app/the system resolution in fullscreen exclusive mode?

If anyone can point me in the right direction. Here is the code I have so far.

//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setUndecorated(true);//To remove the bars around the frame.
frame.setResizable(false);//resizability causes unsafe operations.

frame.validate();

//actually applies the fullscreen.
GaphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);

Upvotes: 2

Views: 6760

Answers (1)

Kerem Baydoğan
Kerem Baydoğan

Reputation: 10722

There are three complex example you may interested in oracle tutorials.

Do you want to use high-performance graphics in the Java development environment? Have you always wanted to program a game, but your images wouldn't move fast enough? Has your slide show program not worked properly because you had no control over the user's display resolution? If you've been asking any of these questions, then the full-screen exclusive mode API, introduced in release 1.4, may be what you're looking for.


CapabilitiesTest demonstrates the different buffering capabilities available for the machine on which it is run.


DisplayModeTest shows a Swing application that uses passive rendering. If full-screen exclusive mode is available, it will enter full-screen exclusive mode. If display mode changes are allowed, it allows you to switch between display modes.


MultiBufferTest enters full-screen mode and uses multi-buffering through an active render loop.

Take a look at this:
oracle.com/tutorial/fullscreen

and this:
oracle.com/tutorial/fullscreen/example

EDIT:

Here is a sample app does what you want:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class DisplayModeChanger extends JFrame {

    private GraphicsDevice device;
    private static JButton changeDM = new JButton("800X600 @ 32 BIT 60HZ");
    private boolean isFullScreenSupported = false;

    public DisplayModeChanger(final GraphicsDevice device) {

        this.device = device;

        setDefaultCloseOperation(EXIT_ON_CLOSE);

        changeDM.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                DisplayMode dm = new DisplayMode(800, 600, 32, 60);
                device.setDisplayMode(dm);
                setSize(new Dimension(dm.getWidth(), dm.getHeight()));
                validate();
            }
        });

    }

    public void goFullScreen() {
        isFullScreenSupported = device.isFullScreenSupported();
        setUndecorated(isFullScreenSupported);
        setResizable(!isFullScreenSupported);
        if (isFullScreenSupported) {
            device.setFullScreenWindow(this);
            validate();
        } else {
            pack();
            setVisible(true);
        }
    }

    public static void main(String[] args) {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice defaultScreen = env.getDefaultScreenDevice();
        DisplayModeChanger changer = new DisplayModeChanger(defaultScreen);
        changer.getContentPane().add(changeDM);
        changer.goFullScreen();
    }
}

Upvotes: 5

Related Questions