java - 为什么我的 GUI 没有显示?

标签 java swing user-interface

我正在使用 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/

相关文章:

java - Hazelcast SQL 接口(interface)性能缓慢 HZ 4.2.2 与 HZ 5.0.2

java - 如何用图像中的蓝色半透明圆替换我的 Android 应用 Google map 半径圆?

java - 动态/Onspot JTextfield 到 JLabel

java - Java Swing 的循环进度条不起作用

java - 在 Android 中将变量传递给新类

java - JAXB 序列化接口(interface)到 XML 问题(Map<String,ISomeInterface> 不工作)

java - 有没有一种方法可以根据文本字段中输入的数据突出显示或为各个表行着色?

python - 检测用户是否点击了 'maximized'按钮

Flutter 如何让 2-Card Carousel Slide with Indicator?

javascript - 按钮填充可用空间,将它们分组到下拉菜单中