gpt4 book ai didi

java - JMenuBar 不显示右侧菜单选项

转载 作者:行者123 更新时间:2023-12-02 06:09:46 27 4
gpt4 key购买 nike

-我正在尝试使用包含“打开”、“运行”、“帮助”等菜单的菜单栏显示 GUI,但我在 GUI 中只能看到菜单"file"

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.miginfocom.swing.MigLayout;

public class test11 extends JFrame {
public test11(String title, int width, int height) {

//setting up frame
setTitle(title);
setSize(width, height);
setLocationRelativeTo(null);
setMinimumSize(new Dimension(700, 500));
setVisible(true);
setLayout(new MigLayout("debug, fillx, gap unrel rel","[grow, fill][fill]","[fill][fill]"));//no idea

//Menubar
JMenuBar m = new JMenuBar();
m.setBackground(new Color(192,192,192));

JMenu op = new JMenu("Open");
op.add(new JMenuItem("Catalogue"));
op.add(new JMenuItem("Read a Paper!"));
JMenuItem find = new JMenuItem("Find...");
find.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));
op.add(find);
JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_E);
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK));
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
op.add(exit);

JMenu run = new JMenu("Run");
run.add(new JMenuItem("Search My System"));
JMenuItem synchr = new JMenuItem("Start Synchronizer", 'S');
synchr.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
run.add(synchr);

JMenu help = new JMenu("Help");
JMenuItem h = new JMenuItem("Help Contents", 'H');
h.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
help.add(h);
help.add(new JMenuItem("Keyboard Shortcut Card"));
help.add(new JMenuItem("About Application"));

m.add(op);
m.add(run);
m.add(help);
setJMenuBar(m);

//Toolbar
JToolBar toolBar = new JToolBar("Draggable");
JButton subject = new JButton("Subject");
toolBar.add(subject);
add(toolBar, "span, height 20:35:50, wrap");

JPanel table = new JPanel();
JPanel sideBar = new JPanel();
add(table, "width 400:600:, dock center, growy");
add(sideBar, "width 250:300:350, dock west, growy");
}

public static void main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new test1("ResearchSoft",1300,700).setVisible(true);
}
});
}
}

-甚至将工具栏按钮更改为“主题”,但它显示“选择”

有人能找出为什么会发生这种奇怪的行为吗?

最佳答案

您已经创建了

的对象
 new test1("ResearchSoft",1300,700).setVisible(true);

但你想创建

的对象
new test11("ResearchSoft",1300,700).setVisible(true);

关于java - JMenuBar 不显示右侧菜单选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21988426/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com