swingworker

Using swingworker to update a JProgressBar during download

我怕爱的太早我们不能终老 提交于 2019-12-20 03:40:50
问题 QUESTION SOLVED!!!!!! Many thanks to trashgod and HoverCraftFullOfEels! I finally got the concept by using the below example and altering it slightly. The alteration allows scaling the progress bar (by default is 100 units). Again, THANK YOU for your patience and willingness to work through this. Means a lot guys, ~Kyte ps - +1's all 'round :) /** @see http://stackoverflow.com/questions/4637215 */ public class Threading_01 extends JFrame { private static final String s = "0.00"; private

Swingworker Timeout

人盡茶涼 提交于 2019-12-20 01:35:08
问题 I am using a SwingWorker to read data over a TCP connection and display when it comes back. new SwingWorker<EnvInfoProto, Void>() { @Override public EnvInfoProto doInBackground() { try { xxx.writeTo(socket.getOutputStream()); return ProtoMsg.parseFrom(socket.getInputStream()); } catch(IOException ignore) { } return null; } @Override public void done() { try { UpdateGui(get()); } catch (Exception ignore) {} } }.execute(); The problem arises when the socket is dead, e.g. after writeTo it waits

updating a JProgressBar while processing

人走茶凉 提交于 2019-12-19 21:42:11
问题 I know the subject has already been seen on many Questions and has been answered, but still, I can't get trough it. I just want to update a progressBar while extracting some stuff of a large xml file. I thought it was enough to have the time-consuming loop in a different thread but ?.. All I managed to get is the progressBar either not showed at all, or updated at the end, just before it's closed. Instanced somewhere near the launch of the application, I have: public class SomeClass { private

Whats the maximum number of swing worker threads that can be run

喜你入骨 提交于 2019-12-18 20:04:12
问题 Is there an upper limit on the number of Swing Worker threads that can be run or is it like as far as the memory supports? Also is this configurable somewhere? 回答1: A SwingWorker is not a thread itself but a task that will be executed in a thread. Usually, you would use an ExecutorService to execute instances of SwingWorker ; this interface also allows to set the number of threads: int n = 20; // Maximum number of threads ExecutorService threadPool = Executors.newFixedThreadPool(n);

Why SwingWorker? Why not just Thread or Runnable?

99封情书 提交于 2019-12-18 18:54:16
问题 What are the advantages of using SwingWorker instead of Thread or Runnable ? 回答1: Thread and Runnable were part of Java 1.0; they're as good as they were back then. The new concurrency classes distill all that's been learned about multi-threading since then (thank you, Doug Lea and others). Writing multi-threaded code is terribly difficult. The new concurrency classes, including SwingWorker, try to make that easier. Start by noting the generics for strong typing. There's a mechanism built in

Timeout a task with Java's SwingWorker

荒凉一梦 提交于 2019-12-18 16:51:19
问题 I am trying to implement a SwingWorker class within my application. Is there a way to set a length of time that after which, the SwingWorker "times out"? I was thinking that maybe throwing an OutOfTime exception that I can catch and then deal with. I'm just not sure how to implement it. Thanks for all your help! 回答1: Why not embed your task within a Runnable, drop it into a new single-threaded ExecutorService and then perform a get() on the resulting Future with an appropriate timeout. That

What is the rationale of SwingWorker?

瘦欲@ 提交于 2019-12-18 13:27:37
问题 For what I can read, it is used to dispatch a new thread in a swing app to perform some "background" work, but what's the benefit from using this rather than a "normal" thread? Is not the same using a new Thread and when it finish invoke some GUI method using SwingUtilities.invokeLater?... What am I missing here? http://en.wikipedia.org/wiki/SwingWorker http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html 回答1: Yes, you can accomplish what a SwingWorker does with vanilla threads

Java GUI threads - SwingWorker

喜夏-厌秋 提交于 2019-12-18 09:31:26
问题 I have a question regarding SwingWorker and Java GUI's. I have several classes which process information, we can call them Foo1 , Foo2 , and Foo3 . This processing can take a very long time. These are all subclasses of Foo , however Foo is not called directly itself (the Foo[x] classes use methods inherited from Foo . In order to keep the EDT free to paint a progress bar, what is the best way to use SwingWorker when keeping my object hierarchy? Is it possible to have wrapper classes such as

Server based SwingWorker does not Stop

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:14:47
问题 I have a boolean variable to control the execution of the server (start/stop) : private boolean ecoute=true; here is my class: sw=new SwingWorker<String,Void> (){ protected String doInBackground() throws Exception { try { server = new ServerSocket(Integer.parseInt(port.getText())); String str1="waiting for connexion.."; String str2="Connexion ok"; log.append(str1+"\n"); PrintWriter out=null; BufferedReader in=null; Socket socClient=null; while(ecoute){ socClient = server.accept(); log.append

Difference between SwingUtilities.invokeLater and SwingWorker<Void, Object>?

ぃ、小莉子 提交于 2019-12-18 07:03:17
问题 What is the difference between: //Some code, takes a bit of time to process (new SomeJFrame()).setVisible(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { (new SomeJWindow()).start();//Start a new thread } }); And: class doGraphics extends SwingWorker<Void, Object> { @Override public Void doInBackground() { //Some code, takes a bit of time to process (new SomeJFrame()).setVisible(true); return null; } @Override protected void done() { (new SomeJWindow()).start(