I would like to create a without frame border, maximum button, minimum button and frame icon.
Call setUndecorated(true)
on your JFrame
.
This method can only be called while the frame is not displayable (see JavaDoc).
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);
}
}
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
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With