如何在 Java 中创建没有边框和标题栏的 JFrame?
要创建一个没有边框和标题栏的 JFrame,请使用 setUndecorated() −
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(400, 300)); frame.setUndecorated(true);
以下是创建没有边框和标题栏的 JFrame 的示例 −
示例
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class SwingDemo {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(400, 300)); frame.setUndecorated(true);
JPanel panel = new JPanel();
panel.add(new JLabel("Demo!"));
panel.add(new JButton(new AbstractAction("Close") {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}));
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP