java - What does a Swing Call mean? -


i have project takes time load create splash screen tells user through progressbar how time take load , show ui, i'm facing problem.

when create splash, shows correctly create , initialize principal frame , freeze until has load.

so, try load principal frame in thread using swingworker (and works) after unknown nullpointerexceptions , reading lot found terrible idea because not creating ui in edt, here stuck.

i know must swing calls in event dispatch thread (edt) , non-swing heavy work in swingworkers initialize swing components of principal frame heavy work so, should do?

i have read question here, specially this, , think have doubts. taking example:

swingutilities.invokeandwait(new runnable() {     public void run() {         new splashscreen();     } }); // code start system (nothing touches gui) swingutilities.invokeandwait(new runnable() {     public void run() {         new mainframe();     } }); //.. etc 

and reading this site says:

the swing framework manages component drawing, updates, , event handlers on edt.

is creating new component swing call? if is, should if new mainframe() take time because project has lot of components initialize?

how tell splash "program loaded 50%"?

what swing call means , how can correct use of invokelater , swingworker? maybe solution obvious or have answer, can't see , apologize if case.

thanks!

you're on right track. don't use invokeandwait (if have only) - use invokelater:

invokeandwait

causes dorun.run() executed synchronously on awt event dispatching thread.

invokelater

causes dorun.run() executed asynchronously on awt event dispatching thread.

consider block wrapped dolater run on edt thread , code wrapped in dooutside invoked in thread (and that's why don't block ui):

edit:

as pointed out in comments add explanations concepts i'll use.


dolater {     // here goes code } 

is concept for:

swingutilities.invokelater(new runnable() {     public void run() {         // here goes code     } }); 

and

dooutside {     // here goes code } 

is concept for:

new thread(new runnable() {     @override     public void run() {         // here goes code     } }).start(); 

dolater {     final mainframe m = new mainframe();     dooutside {         // handle heavy operation         final int result = 1;         dolater {             m.setresult(result);         }     } } 

conclusion: touches swing in way must run on edt. if want update percentages:

dolater {     final mainframe m = new mainframe();     dooutside {         // handle progress         for(int = 0; < somesize; ++i) {             final int progress = i;             dolater {                 m.getprogressbar().setprogress(progress);             }          }     } } 

i hope understand concept now. swingworker exectly dooutside === doinbackground & dolater === done/progress

btw. code above real code: lookup griffon framework in groovy.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -