2016-06-11 12 views
0

ich müde, um einen Text in eine Jprogress bar zu setzen, indem setString Methode .. Aber es war also nicht ... Was kann ich tun, dass für .. hier ist mein Code ...Wie setze ich einen Text in eine JProgress Bar?

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 

class MyFrame extends JFrame{ 
    JProgressBar pro_bar = new JProgressBar(0,100); 
    MyFrame(){ 
     pro_bar.setSize(400,20); 
     pro_bar.setLocation(50,65); 
     add(pro_bar); 
     setLayout(null);  
     setSize(500,150); 
     setResizable(false); 
     setDefaultCloseOperation(3); 
     setLocationRelativeTo(null); 
     setVisible(true); 
     for(int i=0;i<100;i++){ 

      pro_bar.setValue(i); 
      pro_bar.setString(null); 

      try {Thread.sleep(100);}catch (Exception e){} 
     } 
    } 
} 
class Demo{ 
    public static void main(String args[]){ 
     System.out.println("hello"); 
     MyFrame f1=new MyFrame(); 
    } 
} 

Antwort

0

Sie Es fehlt nur eine Sache.

pro_bar.setStringPainted(true); 
pro_bar.setValue(i); 
pro_bar.setString(i +"%"); 

Set setStringPainted Wert true bevor legen Sie den String und den Wert.