Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse-Java导入似乎丢失了?_Java_Eclipse_Jmenubar - Fatal编程技术网

Eclipse-Java导入似乎丢失了?

Eclipse-Java导入似乎丢失了?,java,eclipse,jmenubar,Java,Eclipse,Jmenubar,我在玩JMenu类,发生了一些意想不到的事情 我运行下面的代码,出现JFrame,但是菜单栏和内容没有显示。 但是,当我用鼠标调整JFrame的大小时,元素就会弹出 import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax

我在玩
JMenu
类,发生了一些意想不到的事情

我运行下面的代码,出现
JFrame
,但是
菜单栏和内容没有显示。
但是,当我用鼠标调整
JFrame
的大小时,元素就会弹出

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame("test");
    frame.setVisible(true);
    frame.setSize(300,300);     
    frame.setLocationRelativeTo(null); // centered on monitor   
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JMenuBar menubar = new JMenuBar();
    frame.setJMenuBar(menubar);
    menubar.setVisible(true);

    JMenu file = new JMenu("File");
    menubar.add(file);

    JMenuItem exit = new JMenuItem("Exit");
    file.add(exit);

    JMenu help = new JMenu("Help");
    menubar.add(help);

    /**
     * Label and text and button
     */
    JLabel label = new JLabel("Hello there");
    JPanel panel = new JPanel();
    frame.add(panel);
    panel.add(label);

    JButton button = new JButton("Submit Button");
    panel.add(button);
    button.setToolTipText("this is my tooltip text");    
  }
}

有人能看到我看不到的可疑的东西吗?

原来只是框架。setVisible(true)


我需要把它放在下面更远的地方。

在添加所有内容之前,帧正在渲染?尝试将调用移动到
frame.setVisible(true)
底部哇,这太简单了。谢谢你指出显而易见的山姆,我需要它。这个答案应该是社区维基(看看你从山姆·杜菲尔那里得到的)