0

I prepared a program using Full Screen Exclusive Mode(FSEM). I set the JFrame's decoration feature as "undecorated" to get rid of title bar and all the insets.

My code is :

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

However, title bar annoyingly remains there. How can I get rid of it? Do I need to set all the insets manually?

  • 1
    Does this answer your question? [JFrame in full screen Java](https://stackoverflow.com/questions/11570356/jframe-in-full-screen-java) – Jeff Holt Aug 28 '21 at 01:23
  • @Jeff Holt, thanks for sharing, but; sorry it does not. I found my own solution and checked it, you can check it too. Somehow setResizable() method blocks hiding of title bar. –  Aug 29 '21 at 14:07
  • @JeffHolt, thanks for sharing, but; sorry it does not. Somehow setResizable() method blocks hiding of title bar. Also if you see the answer in your own link, I used all code parts in mine too, which means they did not worked. I found my own solution and checked it, you can check it too, so who said that my question is closed due to duplication? It is like that someone says me "You ask the same question and your answer code does not work". I am refused to accept this. Who is the admin here? Please check, reverse closing and remove unrelevant "[duplicate]" word from the title. –  Aug 29 '21 at 14:24
  • Chan's answer at that link refers to setting resizable to false. The right thing to do is upvote that answer rather than offer your own. – Jeff Holt Aug 29 '21 at 19:06
  • But if you believe you have a case for an appeal, then you should post a question at the [meta SO site](https://meta.stackoverflow.com/) asking for a review. They'll be happy to do so. – Jeff Holt Aug 29 '21 at 19:15
  • Dear @JeffHolt , i think you read below my solution wrong ! I said that "when I commented out/disable the setresizable(false): ", i.e. when I DELETE resizable(false) line problem solved. Problem is not adding setResizable(false), deleting it. Chan does not suggest deleting it, he/she adds it! Not the same thing ! I understood that you neither read nor try the code or the solution. –  Aug 30 '21 at 12:57

1 Answers1

1

I found the reason :

setResizable(false);

When I comment out the above code, it works!

Mureinik
  • 297,002
  • 52
  • 306
  • 350