我写了一个swing的测试界面但是进度条显示不了哪位帮忙看一下啊小弟先谢谢了啊 关键是要打印的语句在等待的时间以后运行package com.fitech;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class Test extends javax.swing.JFrame { {
// Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager
.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
} private JProgressBar proBar; private JButton view; private JButton hidden; private JLabel lblMsg; /**
 * Auto-generated main method to display this JFrame
 */
public static void main(String[] args) {
Test inst = new Test();
inst.setVisible(true);
} public Test() {
super();
initGUI();
} private void initGUI() {
try {
getContentPane().setLayout(null);
this.setTitle("\u8fdb\u5ea6\u6761\u6d4b\u8bd5");
{
proBar = new JProgressBar();
getContentPane().add(proBar);
proBar.setBounds(56, 70, 245, 14);
proBar.setIndeterminate(true);
proBar.setVisible(false);
proBar.setStringPainted(true);
}
{
lblMsg = new JLabel();
getContentPane().add(lblMsg);
lblMsg.setBounds(35, 28, 91, 21);
lblMsg.setText("\u8fdb\u5ea6\u6761\u6d4b\u8bd5\uff1a");
}
{
view = new JButton();
getContentPane().add(view);
view.setText("\u663e\u793a\u8fdb\u5ea6\u6761");
view.setBounds(147, 28, 105, 28);
view.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
viewActionPerformed(evt);
}
});
}
{
hidden = new JButton();
getContentPane().add(hidden);
hidden.setText(" \u9690\u85cf\u8fdb\u5ea6\u6761");
hidden.setBounds(273, 28, 105, 28);
hidden.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
hiddenActionPerformed(evt);
}
});
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
} private void viewActionPerformed(ActionEvent evt) { proBar.setVisible(true); try {
new Thread() {
public void run() {
try {
showMessage("step one...");
Thread.sleep(3000);
showMessage("\nstep two...");
Thread.sleep(3000);
showMessage("\nfinished.");
Thread.sleep(3000);
} catch (InterruptedException ie) {
// ignored
}
}
}.start(); } catch (Exception ex) {
ex.printStackTrace();
} // 如果有这句的话,进度条就不能显示
// proBar.setVisible(false);
System.out.println("执行完以上的语句在打印!!!");//立马打印的,解决不了这个问题    } private void hiddenActionPerformed(ActionEvent evt) { proBar.setVisible(false);
} private void showMessage(final String msg) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
proBar.setString(msg);
}
});
}}

解决方案 »

  1.   

    沒太明白你的意思   你把System.out.println("执行完以上的语句在打印!!!");放在這個后面  是不是這樣的效果
                                showMessage("step one...");
                            Thread.sleep(3000);
                            showMessage("\nstep two...");
                            Thread.sleep(3000);
                            showMessage("\nfinished.");
                            Thread.sleep(3000);
                            System.out.println("执行完以上的语句在打印!!!");