How to remove title bar in JFrame

CanCeylan picture CanCeylan · Jan 2, 2012 · Viewed 66.4k times · Source

I'm using the following code for practising,

http://docs.oracle.com/javase/tutorial/uiswing/examples/layout/BorderLayoutDemoProject/src/layout/BorderLayoutDemo.java

I also add

frame.setSize(frame.getMaximumSize());

in createAndShowGUI() method,

What is more I want this window not to have the title bar, close and minimize buttons.

I tried the following code,

frame.setUndecorated(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

If I added this code before the pack(), it goes into infine loop with this exception Exception in thread "AWT-EventQueue-0" java.lang.NegativeArraySizeException

If I added the last line of createAndShowGUI() method it throws Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable.

What should I do ?

Thanks.

Answer

Joop Eggen picture Joop Eggen · Jan 2, 2012
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Already there
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setUndecorated(true);