Java - 如何去掉标题栏?

Java - How to get rid of title bar?

我准备了一个使用全屏独占模式 (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);
            
        }
    }

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

我找到原因了:

setResizable(false);

当我注释掉上面的代码时,它起作用了!