swingworker

How should I handle exceptions when using SwingWorker?

▼魔方 西西 提交于 2019-12-03 16:13:49
问题 I use SwingWorker in Java 6 to avoid running long-running code on the event dispatch thread. If the call to get() in my done() method returns an exception, what is an appropriate way of handling the exception? I'm particularly concerned about possible InterruptedExceptions. The JavaDoc example simply ignores the exception but I've learnt over the years that swallowing exceptions leads to hard-to-debug code. A sample usage is as follows: new SwingWorker<String, Void>() { @Override protected

ability to get the progress on a Future<T> object

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 11:43:14
问题 With reference to the java.util.concurrent package and the Future interface I notice (unless I am mistaken) that the ability to start a lengthy tasks and be able to query on the progress only comes with the SwingWorker implementing class. This begs the following question: Is there a way, in a non-GUI, non-Swing application (imaging a console application) to start a lengthy task in the background and allow the other threads to inspect the progress ? It seems to me that there is no reason why

SecondaryLoop instead of SwingWorker?

a 夏天 提交于 2019-12-03 07:40:38
From the documentation for SecondaryLoop , it is not clear when you should use this new feature instead of a SwingWorker , a few examples of interesting cases would be useful. The intent of SecondaryLoop is basically the same as SwingWorker. However, using SecondaryLoop can be less hairy than chaining together multiple SwingWorkers. Take a look at Hidden Java 7 Features – SecondaryLoop for a detailed explanation & example. 来源: https://stackoverflow.com/questions/10196809/secondaryloop-instead-of-swingworker

How should I handle exceptions when using SwingWorker?

被刻印的时光 ゝ 提交于 2019-12-03 04:40:52
I use SwingWorker in Java 6 to avoid running long-running code on the event dispatch thread. If the call to get() in my done() method returns an exception, what is an appropriate way of handling the exception? I'm particularly concerned about possible InterruptedExceptions. The JavaDoc example simply ignores the exception but I've learnt over the years that swallowing exceptions leads to hard-to-debug code. A sample usage is as follows: new SwingWorker<String, Void>() { @Override protected String doInBackground() throws Exception { // do long-running calculation return result; } @Override

ability to get the progress on a Future<T> object

泪湿孤枕 提交于 2019-12-03 02:08:14
With reference to the java.util.concurrent package and the Future interface I notice (unless I am mistaken) that the ability to start a lengthy tasks and be able to query on the progress only comes with the SwingWorker implementing class. This begs the following question: Is there a way, in a non-GUI, non-Swing application (imaging a console application) to start a lengthy task in the background and allow the other threads to inspect the progress ? It seems to me that there is no reason why this capability should be limited to swing / GUI applications. Otherwise, the only available option, the

Concurrent task updating complex object JavaFX - swingworker equivalent?

自闭症网瘾萝莉.ら 提交于 2019-12-02 22:07:39
问题 I want to run a task in background updating intermediate results in the view.I am trying to implement MVC JavaFX application. The task is defined in the Model. I want to send to the main threath partial results in order to show them in the View. I use updateValue() to do so. Also, I define object property and a listener in the controller. My problem: The method changed() from the listener, is not being fired each time that updateValue() is executed in the Task. Why? How can I force it to do

SwingWorker exceptions lost even when using wrapper classes

我的梦境 提交于 2019-12-02 21:05:42
I've been struggling with the usability problem of SwingWorker eating any exceptions thrown in the background task, for example, described on this SO thread . That thread gives a nice description of the problem, but doesn't discuss recovering the original exception. The applet I've been handed needs to propagate the exception upwards. But I haven't been able to even catch it. I'm using the SimpleSwingWorker wrapper class from this blog entry specifically to try and address this issue. It's a fairly small class but I'll repost it at the end here just for reference. The calling code looks

Updating GUI with SwingWorker

送分小仙女□ 提交于 2019-12-02 19:51:21
问题 I posted a question yesterday about preventing the UI from freezing when using a scheduledexecutorservice here What should I do in order to prevent the UI from freezing(scheduledexecutorservice) and most people suggested using SwingWorker instead of scheduledexecutorservice. However, I've been stuck since then trying to figure out how a SwingWorker thread would work in my case. I have the following pseudocode: createGraph(){ if(rule1) n = new Node() graph.add(n) animateGraph() createGraph()

SwingWorker with FileReader

怎甘沉沦 提交于 2019-12-02 15:23:51
问题 I have problem about applied SwingWorker with FileReader and my point is I need to implement FileReader with SwingWorker to make my UI Show the text from the file and this is my code class Read1 extends SwingWorker<String,String>{ protected Void doInBackground() throws Exception{ FileReader read = new FileReader("msg.txt"); BufferedReader in = new BufferedReader(read); String s; s=in.readLine(); System.out.println(s); return s; } protected void done() { try{ String show; show=get(); textArea

Java SwingWorker while using SWT

空扰寡人 提交于 2019-12-02 14:23:38
I have a problem as follows: I've written a simple minimalistic Application that utilizes the SWT for the GUI. In a specific tab, where it displays a table that get's filled with Informition via a REST Api Call. Additionaly, i have another method to export this table into a CSV-file. This works absolutely fine. Now I need some kind of autoupdate/-export for which I implemented a Swing-Worker like this: protected class AutoExportWorker extends SwingWorker<Integer, String> { @Override public Integer doInBackground() throws Exception { System.out.println("Worker Start!"); while (true) { System