I’m using the following code for practising,
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.
The title bar can be removed by calling
setUndecorated(true)on theFrameorJFrameinstance, i.e. by setting the "undecorated" property totrue. This removes both the title bar and the surrounding frame.Here’s the required code for the question:
On a packed
JFramesetUndecorated(true)must be called beforepack()is being called, either directly or indirectly, for instance throughsetVisible(true).Apparently it is not possible to remove the title bar after the packing is performed, this is the documentation of
Frame#setDecorated(boolean):However, you can call
Window#dispose()on theFrameorJFrameand then pack it again, which causes the layout of the components within theJFrameto be refreshed.