有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么我的GUI不显示?

我正在使用inteliJ编写一个文件传输程序,现在正在使用Swing开发GUI。我已经在swing中制作了很多程序,但由于某些原因,我不明白为什么在运行程序时我的GUI没有出现。一切都很好

    public class stage  {

    JPanel mainContainer = new JPanel();
    JPanel window = new JPanel();
    JButton loadButton = new JButton();
    JButton saveButton = new JButton();
    JTextPane cmdOut = new JTextPane();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu();
    JMenuItem exitButton = new JMenuItem("exit");

public void display(){
    mainContainer.setVisible(true);
    mainContainer.add(window);
    mainContainer.add(menuBar);
    menuBar.add(menu);
    menu.add(exitButton);
    window.setLayout(new GridBagLayout());
    window.add(loadButton);
    window.add(saveButton);
    window.add(cmdOut);
    cmdOut.setText("TEST");
    window.setVisible(true);



}


}

这是我在另一节课上的主要方法

public static void main(String[] args) throws IOException {
    stage stage = new stage();

    stage.display();




}

共 (1) 个答案

  1. # 1 楼答案

    为什么不把主面板放进JFrame中,这样JFrame就可以容纳主面板,而主面板可以容纳其他所有东西呢