作者GrayAngel (灰天使)
看板java
标题[问题] how to update JProgressBar in a loop?
时间Tue Nov 28 01:33:25 2006
假设我按了一个button会开始跑一个for loop
然後我想要同时显示loop的进度..
大概像下面这样子... 可是ProgressBar只会在loop跑完的时候才会update
也就是一次从0% 跳到 100%
请问有什麽办法可以解决吗?
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JProgressBar pro = new JProgressBar(0, 100000);
JFrame frame = new JFrame();
frame.add(pro);
frame.setSize(50,50);
frame.setVisible(true);
pro.setStringPainted(true);
Runnable runner = new Runnable(){
public void run(){
int val = pro.getValue();
pro.setValue(val+1);
}
};
for(int i=0;i<100000;i++){
//operations..
SwingUtilities.invokeLater(runner);
}
}
});
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 69.255.250.222