下拉菜单项会被panel隐藏掉,怎么才能正常显示
code:public class TestMenu extends JMenuBar { JFrame y;
public TestMenu (JFrame f){
this.y=f;
} public void load() {
JMenu m=new JMenu("File");
JMenuItem item1=new JMenuItem("Start");
JMenuItem item2=new JMenuItem("Exit");
m.add(item1);
m.add(item2);
this.add(m);
y.setJMenuBar(this);
} public static void main(String[] args) {
JFrame f=new JFrame();
JScrollPane srollPane=new JScrollPane();
Panel panel=new Panel();
panel.setSize(300, 300);
panel.setBackground(Color.GRAY);
srollPane.add(panel);
f.add(srollPane);
TestMenu m=new TestMenu(f); //菜单
m.load();
f.setSize(300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
code:public class TestMenu extends JMenuBar { JFrame y;
public TestMenu (JFrame f){
this.y=f;
} public void load() {
JMenu m=new JMenu("File");
JMenuItem item1=new JMenuItem("Start");
JMenuItem item2=new JMenuItem("Exit");
m.add(item1);
m.add(item2);
this.add(m);
y.setJMenuBar(this);
} public static void main(String[] args) {
JFrame f=new JFrame();
JScrollPane srollPane=new JScrollPane();
Panel panel=new Panel();
panel.setSize(300, 300);
panel.setBackground(Color.GRAY);
srollPane.add(panel);
f.add(srollPane);
TestMenu m=new TestMenu(f); //菜单
m.load();
f.setSize(300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
this.y = f;
} public void load() {
JMenu m = new JMenu("File");
JMenuItem item1 = new JMenuItem("Start");
JMenuItem item2 = new JMenuItem("Exit");
m.add(item1);
m.add(item2);
this.add(m);
y.setJMenuBar(this);
} public static void main(String[] args) {
JFrame f = new JFrame();
JScrollPane srollPane = new JScrollPane();
Panel panel = new Panel();
panel.setSize(300, 300);
panel.setBackground(Color.GRAY);
srollPane.add(panel);
f.add(srollPane); TestMenu m = new TestMenu(f);
m.load(); f.setSize(300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}