如何在全屏独占模式下设置Java应用程序/系统分辨率的分辨率?

dav*_*nes 2 java fullscreen

如果有人能指出我正确的方向.这是我到目前为止的代码.

//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);
Run Code Online (Sandbox Code Playgroud)

Ker*_*ğan 5

有三个复杂的例子你可能对oracle教程感兴趣.

您想在Java开发环境中使用高性能图形吗?你一直想编写一个游戏,但你的图像移动速度不够快吗?您的幻灯片放映程序是否无法正常工作,因为您无法控制用户的显示分辨率?如果您一直在询问这些问题,那么1.4版中引入的全屏独占模式API可能正是您所需要的.


CapabilitiesTest演示了运行它的机器可用的不同缓冲功能.


DisplayModeTest显示使用被动渲染的Swing应用程序.如果可以使用全屏独占模式,它将进入全屏独占模式.如果允许显示模式更改,则允许您在显示模式之间切换.


MultiBufferTest进入全屏模式,并通过活动渲染循环使用多缓冲.

看看这个:
oracle.com/tutorial/fullscreen

这个:
oracle.com/tutorial/fullscreen/example

编辑:

这是一个示例应用程序做你想要的:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)