Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFrame without frame border, maximum button, minimum button and frame icon

Tags:

java

swing

I would like to create a without frame border, maximum button, minimum button and frame icon.

like image 269
Chan Pye Avatar asked Jan 06 '10 08:01

Chan Pye


4 Answers

Call setUndecorated(true) on your JFrame.

This method can only be called while the frame is not displayable (see JavaDoc).

enter image description here

like image 106
Peter Lang Avatar answered Oct 22 '22 07:10

Peter Lang


This code Explains how you can achieve it.

Note: setUndecorated(true); statement in the constructor.

You cannot undecorate the Frame while it is already displayed.

public class MyFrame extends JFrame {

private JPanel contentPane;
private JTextField textField;

/**
 * Launch the application.
 */
public static void main(String[] args) {

                MyFrame frame = new MyFrame();
                frame.setVisible(true);

}
/**
 * Create the frame.
 */
public MyFrame() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBackground(Color.ORANGE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));


    /* important Statement */
    setUndecorated(true);
}

}

Frame without Border

like image 31
Vishwanath gowda k Avatar answered Oct 22 '22 08:10

Vishwanath gowda k


Inside the constructor you can put code setUndecorated(true) it will disappear Frame.

For example: //This is constructor

public freak() {    
    super("Images");
    panel = new JPanel();
    ImageIcon image = new ImageIcon("C:\\Users\\shilu.shilu-PC\\Desktop\\2.jpg");
    label = new JLabel(image);
    add(panel);
    add(label);

    //Main thing is this one
    setUndecorated(true);
    //Just add this code in your constructor
}
like image 2
sophin Avatar answered Oct 22 '22 09:10

sophin


You can the java.awt.Window class. A Window is like a JFrame, but with no borders.

Note that the Window class constructor needs a Frame (java.awt.Frame) as an argument, but you can set it to null. You can also extend the Window class to customize it like this:

public class MyWindow extends Window{
   public MyWindow(){
      super(null); // creates a window with no Frame as owner
      setBounds(x, y, width, height);
      setVisible(true);
   }
}

In main, you can create an instance of MyWindow instead of Window.

public static void main (String[] args) {
    Window window = new MyWindow();
    // Other stuff in main
}

I hope this helps!

like image 1
Ramdane Avatar answered Oct 22 '22 09:10

Ramdane