gpt4 book ai didi

java - JFrame 显示为空

转载 作者:行者123 更新时间:2023-12-01 12:37:55 27 4
gpt4 key购买 nike

我在方法执行期间显示一个简单的框架,只有一个面板和两个组件。

这是我的代码:

public void sarPPRuning() {
JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);

sarppRun = new JFrame("Please wait");
JPanel pan = new JPanel(new GridBagLayout());
pan.add(new JLabel("SARPP is running, please wait"),
new GridBagConstraints(0, 0, 1, 1, 1, 1,
GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3),
0, 0));
pan.add(progressBar, new GridBagConstraints(0, 1, 1, 1, 1, 1,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(3, 3, 3, 3), 0, 0));
sarppRun.getContentPane().add(pan, BorderLayout.CENTER);
sarppRun.setSize(400, 100);
sarppRun.setVisible(true);
sarppRun.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

这里调用这个方法:

_vet.sarPPRuning();
execSARPP()

其中_vet是扩展ViewGuiDialog的类的实例

我的JFrame出现了,但在execSARPP函数完成之前它是空的!!!

最佳答案

当我获取你的代码并自行运行它时,

public static void main(String[] args) {
JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);

JFrame sarppRun = new JFrame("Please wait");
JPanel pan = new JPanel(new GridBagLayout());
pan.add(new JLabel("SARPP is running, please wait"),
new GridBagConstraints(0, 0, 1, 1, 1, 1,
GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3),
0, 0));
pan.add(progressBar, new GridBagConstraints(0, 1, 1, 1, 1, 1,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(3, 3, 3, 3), 0, 0));
sarppRun.getContentPane().add(pan, BorderLayout.CENTER);
sarppRun.setSize(400, 100);
sarppRun.setVisible(true);
sarppRun.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

它按预期工作,我得到带有移动进度条的 JFrame, SARPP JFrame

关于java - JFrame 显示为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25405780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com