我正在使用 inteliJ 编写文件传输程序,并且现在正在使用 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();
}
最佳答案
为什么不将主面板放入 JFrame 中,以便 JFrame 包含主面板,而主面板包含其他所有内容?
关于java - 为什么我的 GUI 没有显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34819271/