java - SwingWorker locks GUI on (unsuccessful) JLabel Icon updating -


ok im struggling unlocking gui locked due separate swingworker thread. program does: initializes webcam, , grabs single frame , displays jlabel icon (doing single grab+display on button click ease, have immense difficulties in doing such operation consecutively in order image processing). aiming obtain such result:

grab frame -> process -> display imageicon of jlabel > ... repeat grab frame >...

i need results while webcam streaming, therefore used swingworker publish , process. in code "processing part" not included not necessary since cant obtain proper continuous frame grabbing. background thread never finish unless cancelled (well thats assumption want process images fast possible maximum frames per second - unless should other way? - guess separate thread single frame grab&process bad idea due fact im aiming 10+ fps). know swingworker thread works, since made tests of saving consecutive images c:\, , did work, gui locked anyway, @ least know thread running , grabbing frames.

generally have 2 problems:

  • no jlabel icon update
  • locked gui

my swingworker code:

private class framestream extends swingworker<void, bufferedimage> {      @override     protected void doinbackground() throws interruptedexception{         bufferedimage processedimage = null;          while (!iscancelled()) {             processedimage = getpic_color(player);             publish(processedimage);              thread.sleep(5000); // made such delay check whether program not "choking" data, not case, without delay everthing same         }                     return null;     }      @override     protected void process(list<bufferedimage> mystuff) {         iterator = mystuff.iterator();           while (it.hasnext()) {             img_field.seticon(new imageicon(mystuff.get(mystuff.size()-1)));         }     }      @override     protected void done() {                     infobar.settext("finished");     } } 

i desperate rewritten code basing on tutorials example: flipper can see ridiculously similar. previous efforts locked gui tried 'tutorial way', nonetheless did not work, pity. im in dead end because have no clue how fix that. im desperate since can see seems same tutorial one, maybe other causes issues: my full code

please help, i'm unable solve myself.

one thing looks little different me process method. rather specifying last image, might wish iterate through images so:

  @override   protected void process(list<bufferedimage> mystuff) {      (bufferedimage bimage : mystuff) {         img_field.seticon(new imageicon(bimage));      }   } 

i'm not sure if make significant difference, believe how process should written. thought -- if bufferedimages large may wish create imageicon in background thread , publish imageicon rather bufferedimage.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -