2016-01-15 205 views
0

我正在使用inteliJ来编写文件传输程序,我正在使用Swing在GUI上工作。我在swing中制作了大量程序,但出于某种原因,我无法弄清楚为什么我运行该程序时不显示GUI。一切都编译得很好。为什么我的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(); 




} 
+2

您从未将'mainContainer'添加到任何窗口。尝试将其粘贴到“JFrame”中。 – azurefrog

+0

Ahhhh该死的,我知道它必须是我忽略的简单东西。队友的欢呼声。 – Remixt

+0

好吧,他走了,评论它,之前我张贴我的答案:( –

回答

2

你为什么不把你的主面板成一个JFrame,让你的JFrame将包含您的主面板,和你的主面板保持一切?