0

Here is my code

import java.awt.*;
import javax.swing.*; 
import java.awt.Color;
import javax.swing.JPanel;

public class FirstFrame extends JFrame {


    //FirstFrame properties

    public FirstFrame(){

        setTitle ("Stacker");
        setSize (380,650);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible (true);
        setUndecorated (true);
        setResizable(false);

    }
public static void main (String[] args){
        new FirstFrame();
    }
}

I'm trying to remove the toolbar above because I want to put buttons in the frame that will contain exit, and play button. Hope you can help me!

tenorsax
  • 21,123
  • 9
  • 60
  • 107
dan
  • 27
  • 1
  • 2

5 Answers5

3

Just change the order of events in your constructor from this:

    setTitle ("Stacker");
    setSize (380,650);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible (true);
    setUndecorated (true);
    setResizable(false);

To this:

    setTitle ("Stacker");
    setSize (380,650);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setUndecorated (true);
    setResizable(false);
    setVisible (true); // move setVisible to the end
BitNinja
  • 1,477
  • 1
  • 19
  • 25
  • thank you so much! sorry if my question is already duplicated/. i just wanna understand it with my own code! thanks :) – dan Feb 23 '14 at 07:35
  • You are welcome! Personally I didn't consider this question a duplicate because you used the correct syntax to make the frame go away, the order was just wrong. – BitNinja Feb 23 '14 at 20:12
3

The main problem is, you've made the frame visible before you've set undecoratable

Disables or enables decorations for this frame.

This method can only be called while the frame is not displayable. To make this frame decorated, it must be opaque and have the default shape, otherwise the IllegalComponentStateException will be thrown. Refer to Window.setShape(java.awt.Shape), Window.setOpacity(float) and Window.setBackground(java.awt.Color) for details

So, instead of...

    setVisible (true);
    setUndecorated (true);

You should try...

    setUndecorated (true);
    setVisible (true);
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • thank you so much! sorry if my question is already duplicated/. i just wanna understand it with my own code! thanks :) – dan Feb 23 '14 at 07:20
1

You have to disable or enable decorations for the frame while the frame is not displayable. See setUndecorated for details. Reverse the order in your code - first call setUndecorated (true); then call setVisible (true);,

tenorsax
  • 21,123
  • 9
  • 60
  • 107
0

Try:

setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);
ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
0

Use frame.setUndecorated(true); but you never set up a frame so just put setUndecorated under setResizable

ImGone98
  • 195
  • 8