【问题标题】:Java - How to get rid of title bar? [duplicate]Java - 如何摆脱标题栏? [复制]
【发布时间】:2021-10-27 18:42:43
【问题描述】:

我使用全屏独占模式 (FSEM) 准备了一个程序。我将 JFrame 的装饰功能设置为“未装饰”以摆脱标题栏和所有插图。

我的代码是:

        public class GameWindow extends JFrame implements WindowListener {

        public GameWindow( ) {
            super("Window");
            DisplayMode origDisplayMode = null;
            GraphicsDevice graphicsDevice= null ;
            GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
            //  put graphical devices into array 
            for(int cnt = 0;cnt < 1;cnt++){
                System.out.println(devices[cnt]);
            }

            //Construct a full-screen object using the first/ active graphicsDevice which has 0 index
            graphicsDevice= devices[0];
            if (graphicsDevice.isFullScreenSupported()){
                // Enter full-screen mode witn an undecorated,non-resizable JFrame object
                setExtendedState(JFrame.MAXIMIZED_BOTH);
                setTitle("FRAME MAX");
                setUndecorated(true);
                setResizable(false);
                graphicsDevice.setFullScreenWindow(this);
                revalidate();
                repaint();
                Toolkit.getDefaultToolkit().sync(); // to make graphics sync for Linux
                System.out.println("OK Full-screen mode is supported");
            } else {
                System.out.println("XX Full-screen mode is not supported");
            }
            origDisplayMode = graphicsDevice.getDisplayMode();
            // get dimensions from display mode 
            Dimension dim=new Dimension(origDisplayMode.getWidth(),origDisplayMode.getHeight());
            setSize(dim);
            setPreferredSize(dim);
            setMinimumSize(dim);
            setLocationRelativeTo(null);
    }

    public static void main(String[] args) {
            AppStarter starter = new AppStarter( args );
            SwingUtilities.invokeLater( starter );
        }
    }

    class AppStarter extends Thread
    {
        private String[] args;

    
        public AppStarter( String[] args )
        {
            this.args = args;
        }
        
        public void run()
        {   //start program here 
            GameWindow gw=new GameWindow();
            gw.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            gw.setVisible(true);
            
        }
    }

但是,令人讨厌的标题栏仍然存在。我怎样才能摆脱它?我需要手动设置所有插图吗?

【问题讨论】:

  • 这能回答你的问题吗? JFrame in full screen Java
  • @Jeff Holt,感谢分享,但是;对不起,它没有。我找到了自己的解决方案并检查了它,您也可以检查它。不知何故 setResizable() 方法阻止隐藏标题栏。
  • @JeffHolt,感谢分享,但是;对不起,它没有。不知何故 setResizable() 方法阻止隐藏标题栏。此外,如果您在自己的链接中看到答案,我也使用了我的所有代码部分,这意味着它们没有工作。我找到了自己的解决方案并检查了它,您也可以检查它,所以谁说我的问题由于重复而被关闭?就像有人说我“你问同样的问题,你的答案代码不起作用”。我拒绝接受这一点。这里的管理员是谁?请检查,反向关闭并从标题中删除不相关的“[重复]”字。
  • Chan 在该链接上的回答是指将 resizable 设置为 false。正确的做法是支持该答案,而不是提供您自己的答案。
  • 但是,如果您认为自己有上诉的理由,那么您应该在meta SO site 上发帖请求审查。他们会很乐意这样做的。

标签: java titlebar


【解决方案1】:

我找到了原因:

setResizable(false);

当我注释掉上面的代码时,它可以工作了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多