天天看點

swing 進度條

1,進度條執行個體

swing 進度條

2,建立一個進度條

swing 進度條

copyprogressbar = new jprogressbar();  

        copyprogressbar.setborderpainted(true);  

        copyprogressbar.setstring(progressinitstr);  

        copyprogressbar.setstringpainted(true);  

3,進度條兩種模式

模式一:百分比模式(determinate mode)

swing 進度條

更新進度條:

swing 進度條

/*** 

     * 測試進度條<br>百分比 

     */  

    public void testprogressbar() {  

        copyprogressbar.setindeterminate(false);//取消"不确定模式"  

        new thread(new runnable() {  

            @override  

            public void run() {  

                copyfilebtn.setenabled(false);  

                int count = 0;  

                copyprogressbar.setforeground(progressdefaultcolor);  

                try {  

                    thread.sleep(50);  

                } catch (interruptedexception e) {  

                    e.printstacktrace();  

                }  

                while (true) {  

                    if(isstop()){  

                        setstop(false);  

                        break;  

                    }  

                    count++;  

                    try {  

                        thread.sleep(50);  

                    } catch (interruptedexception e) {  

                        e.printstacktrace();  

                    copyprogressbar.setstring(count + "%");  

                    copyprogressbar.setvalue(count);  

                    if (count >= 100) {  

                        copyprogressbar.setforeground(color.green);  

                copyfilebtn.setenabled(true);  

            }  

        }).start();  

    }  

模式二:不确定模式

swing 進度條

 啟動進度條:

swing 進度條

     * 左右移動<br> 

     * 将進度條設定為不确定模式 

    public void testindeterminate() {  

        copyprogressbar.setstringpainted(false);  

        copyprogressbar.setindeterminate(true);  

4,說明

(1)copyprogressbar.setstring(progressinitstr);

copyprogressbar.setstringpainted(true);

作用:在進度條上顯示百分比的文字

(2)停止不确定模式:

swing 進度條

public void stopindeterminate(){  

        copyprogressbar.setindeterminate(false);  

        copyprogressbar.setvalue(100);  

源代碼:

<a target="_blank" href="http://pan.baidu.com/s/1i3s9cff">http://pan.baidu.com/s/1i3s9cff</a>

參考:http://hw1287789687.iteye.com/blog/2003105