在方法执行过程中,我只有一个简单的框架,只有一个面板有两个组件。
所以这是我的代码:
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
功能完成之前它是空的!!!
答案 0 :(得分:1)
当我接受你的代码并自行运行时,
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,