【问题标题】:How to set resolution of a Java app/the system resolution in fullscreen exclusive mode?如何在全屏独占模式下设置 Java 应用程序的分辨率/系统分辨率?
【发布时间】:2013-04-04 13:49:37
【问题描述】:

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

//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);

【问题讨论】:

    标签: java fullscreen


    【解决方案1】:

    您可能对 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();
        }
    }
    

    【讨论】:

    • 没有提到分辨率。我有一个全屏应用,但找不到如何更改分辨率。
    • 如果您需要更改系统分辨率,请在您的问题中提及。我将根据分辨率更改方案编辑我的问题。
    • 我只需要更改我认为的应用显示模式的分辨率,而不是系统。
    • 我的示例代码更改了系统屏幕分辨率。我不知道您所说的resolution of the app's display mode 是什么意思。试试看,让我知道它是否有效。谢谢。
    • 您对 krmby 的帮助很大!谢谢!这是我正在寻找的显示模式类。
    猜你喜欢
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多