如何在 Java 中创建无标题和无边框的 JFrame?
若要创建无标题和无边框 JFrame,请使用 setUndecorated() 方法,并将其设置为 TRUE −
JFrame frame = new JFrame("Register!"); frame.setUndecorated(true);
以下是创建无标题和无边框 JFrame 的示例 −
示例
package my; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Register!"); JLabel label1, label2, label3; frame.setLayout(new GridLayout(2, 2)); label1 = new JLabel("Id", SwingConstants.CENTER); label2 = new JLabel("Age", SwingConstants.CENTER); label3 = new JLabel("Password", SwingConstants.CENTER); JTextField emailId = new JTextField(20); JTextField age = new JTextField(20); JPasswordField passwd = new JPasswordField(); passwd.setEchoChar('*'); frame.add(label1); frame.add(label2); frame.add(label3); frame.add(emailId); frame.add(age); frame.add(passwd); frame.setUndecorated(true); frame.setSize(550, 400); frame.setVisible(true); } }
输出
广告