Java Swing - 如何創(chuàng)建沒有邊框和標(biāo)題欄的JFrame
我們想知道如何創(chuàng)建沒有邊框和標(biāo)題欄的JFrame。
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 Main {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setUndecorated(true);
JPanel panel = new JPanel();
panel.add(new JLabel("Stackoverflow!"));
panel.add(new JButton(new AbstractAction("Close") {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}));
f.add(panel);
f.pack();
f.setVisible(true);
}
}