【问题标题】:JMenuBar is not visibleJMenuBar 不可见
【发布时间】:2012-06-28 15:45:04
【问题描述】:

我有以下设置 GUI 的功能。

public void go() {

    JFrame frame = new JFrame("Simplex RP Client V1.1 Beta");
    JPanel mainPanel = new JPanel();
    incoming = new JTextArea(15,50);
    incoming.setLineWrap(true);
    incoming.setWrapStyleWord(true);
    incoming.setEditable(false);
    JScrollPane qScroller = new JScrollPane(incoming);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    outgoing = new JTextField(50);






//      rpMode = new JComboBox("OOC", "IC", "IT", "ME");
    charName = new JTextField(30);
    charName.setText("Character Name");
    JButton sendButton = new JButton("Send");
    sendButton.addActionListener(new SendButtonListener());
    outgoing.addActionListener(new SendButtonListener());
    mainPanel.add(qScroller);
    mainPanel.add(outgoing);
    mainPanel.add(sendButton);
    mainPanel.add(BorderLayout.SOUTH, charName);
//  setUpNetworking();
    Thread readerThread = new Thread(new IncomingReader());
    readerThread.start();

    JMenuBar menubar = new JMenuBar();
    frame.setJMenuBar(menubar);
    JMenu file = new JMenu("File");
    JMenuItem connect = new JMenuItem("Connect");
    file.add(connect);


        frame.getContentPane().add(BorderLayout.NORTH, menubar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
        frame.setSize(577,375);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
} // close go

我似乎无法显示我的 JMenuBar。我已经尝试修复它几个小时了,我是 Java 新手。任何帮助将非常感激。我真的没什么好说的,我敢肯定这是一个简单的问题。

【问题讨论】:

    标签: java swing jmenu jmenubar


    【解决方案1】:

    您永远不会将您的 JMenu 添加到您的 JMenuBar:menuBar.add(file);

    【讨论】:

    • 它有效,但是在我的程序顶部有一个看起来很糟糕的空间。我显然也在某个地方搞砸了,第二次。 i.imgur.com/uPZ6Q.png
    • 哦,我找到了,这是我的一个愚蠢的错误。当我试图让菜单栏显示时,我的代码中有这个。 frame.getContentPane().add(BorderLayout.NORTH, menubar);
    猜你喜欢
    • 1970-01-01
    • 2014-04-04
    • 2017-09-26
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多