0
有一個簡單的代碼:JMenuBar和JaayeredPane中JBatton的JPanel。問題是JLayeredPane與JMenuBar重疊。如何解決它?如何在沒有setBounds的情況下使用帶有JLayeredPane的JMenuBar?
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
public class Simple extends JFrame{
public Simple() {
super("Simple");
setSize(1000, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
JMenuBar menu = new JMenuBar();
JMenu File = new JMenu("File");
menu.add(File);
setJMenuBar(menu);
JPanel panel = new JPanel();
panel.setSize(1000, 500);
JButton button = new JButton("Button");
panel.add(button);
getLayeredPane().add(panel,JLayeredPane.DEFAULT_LAYER);
}
public static void main(String[] args) {
new Simple();
}
}