【发布时间】:2010-01-06 08:03:58
【问题描述】:
我想创建一个无边框、最大按钮、最小按钮和边框图标。
【问题讨论】:
我想创建一个无边框、最大按钮、最小按钮和边框图标。
【问题讨论】:
在您的JFrame 上致电setUndecorated(true)。
此方法只能在框架不可显示时调用(参见JavaDoc)。
【讨论】:
setUndecorated(true); 放在构造函数MyJframe() 的开头。
此代码说明了如何实现它。
注意:setUndecorated(true);构造函数中的语句。
当框架已经显示时,您不能取消装饰。
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);
}
}
【讨论】:
在构造函数中你可以输入代码 setUndecorated(true) 它会消失 Frame.
例如: //这是构造函数
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
}
【讨论】:
您可以使用java.awt.Window 类。 Window 类似于 JFrame,但没有边界。
请注意,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);
}
}
在main 中,您可以创建MyWindow 的实例而不是Window。
public static void main (String[] args) {
Window window = new MyWindow();
// Other stuff in main
}
我希望这会有所帮助!
【讨论】:
swing 标签。 2) Swing 提供了一个JWindow。如果您删除或(最好)编辑您的答案,您可能会避免一些反对票。 ;)
使用方法frame.getContentPane(); 此方法返回任何帧的内部内容。 但是您需要将其转换为 JPanel。 PrintUI 使用 JPanel 而不是 JFrame....
【讨论】: