Java JFrame 无边框、最大按钮、最小按钮和框架图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2011601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:30:00  来源:igfitidea点击:

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

javaswing

提问by Chan Pye

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

我想创建一个无边框、最大按钮、最小按钮和框架图标。

采纳答案by Peter Lang

Call setUndecorated(true)on your JFrame.

致电setUndecorated(true)您的JFrame.

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

此方法只能在框架不可显示时调用(请参阅JavaDoc)。

enter image description here

在此处输入图片说明

回答by Ramdane

You can the java.awt.Windowclass. A Windowis like a JFrame, but with no borders.

你可以java.awt.Window上课。AWindow类似于 a JFrame,但没有边界。

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

请注意,Window类构造函数需要一个Frame( java.awt.Frame) 作为参数,但您可以将其设置为null. 您还可以扩展Window该类以自定义它,如下所示:

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 MyWindowinstead of Window.

在 中main,您可以创建一个MyWindow代替 的实例Window

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

I hope this helps!

我希望这有帮助!

回答by Vishwanath gowda k

This code Explains how you can achieve it.

此代码解释了如何实现它。

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

注意:setUndecorated(true); 构造函数中的语句。

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

无边框框架

回答by Harsh Rawat

Use method frame.getContentPane(); this method return inside content of any frame. But you need to cast it into a JPanel. PrintUI using JPanel not JFrame....

使用方法 frame.getContentPane(); 此方法返回任何框架的内部内容。但是您需要将其转换为 JPanel。PrintUI 使用 JPanel 而不是 JFrame ....

回答by sophin

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

在构造函数中,您可以放置​​代码 setUndecorated(true) 它将消失 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
}