Sunday, 15 September 2013

java - Change the jprogressbar in an other class -



java - Change the jprogressbar in an other class -

i´ve got project , want alter value of progressbar phone call class. how implement this?

static class buttonactionlistener implements actionlistener { @override public void actionperformed( actionevent e ) { new thread( new runnable() { @override public void run() { ( int = 1; <= bar.getmaximum(); ++i ) { final int j = i; swingutilities.invokelater( new runnable() { @override public void run() { bar.setvalue( j ); } } ); } } } ).start(); } }

you phone call bar.setvalue(...) alter progress.

however, beware can safely code runs on swing event listener thread. calling method thread liable lead obscure failures happen occasionally, hard test for, , hard track down.

using swingutilities.invokelater(...) create alter right approach. can code has access bar reference. example, expose via getter.

java jprogressbar

No comments:

Post a Comment