swingworker

SwingWorker not responding

余生颓废 提交于 2019-11-26 23:17:17
What I am trying to do ? At the click of the Start JButton , the SwingWorker will execute. Inside the doInBackground() method, I am passing each index of arrNames , to the publish() method, so that it can be displayed inside the JTextArea . What happened ? If I do not keep line System.out.format("Counter : %d%n", counter); as a comment , in my doInBackground() method of the SwingWorker , then the SwingWorker is working as expected . Though if I comment it out , then the SwingWorker stops responding . Am I doing something wrong ? Java Version : java version "1.7.0_25" Java(TM) SE Runtime

SwingWorker: when exactly is called done method?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 22:57:20
问题 Javadoc of the done() method of SwingWorker: Executed on the Event Dispatch Thread after the doInBackground method is finished. I've clues that it is not true in the case of canceled worker. Done is called in each case (normal termination or cancellation) but when cancelled it is not enqueued to the EDT, as it happens for normal termination. Is there some more precise analisis on when done is called in the case that a SwingWorker is cancelled? Clarification: this question is NOT on how to

Swing Worker Threads Not Concurrent

半城伤御伤魂 提交于 2019-11-26 22:03:27
问题 It seems that when I instantiate 12 Swing Worker threads, the first six starts to complete its task, it finishes AND then the last six starts and finishes. The behavior I'm looking for is all 12 threads start working at the same time & finish at the same time. I have the following: for (int i = 0; i < 12; i++ ) { myTask m = new Mytask(i, START); m.execute(); } The myTask m will increment a progress bar from 0 - 100 in increments of 25. I'm getting outlandish behavior that the first six

Understanding Java ExecutorService

蓝咒 提交于 2019-11-26 21:43:08
问题 I am trying the learn how to use executorservice of Java, I was reading the following discussion Java thread simple queue In this there is a sample example ExecutorService service = Executors.newFixedThreadPool(10); // now submit our jobs service.submit(new Runnable() { public void run() { do_some_work(); } }); // you can submit any number of jobs and the 10 threads will work on them // in order ... // when no more to submit, call shutdown service.shutdown(); // now wait for the jobs to

Prevent Swing GUI locking up during a background task

三世轮回 提交于 2019-11-26 20:47:43
I have a swing application which stores a list of objects. When the users clicks a button, I want to perform two operations on each object in the list, and then once that is complete, graph the results in a JPanel. I've been trying SwingWorker, Callable & Runnable to do the processing, but no matter what I do, while processing the list (which can take up to a few minutes, as it is IO bound), the GUI is locked up. I have a feeling it's probably the way I'm calling the threads or something, or could it be to do with the graphing function? That isn't threaded as it is very quick. I have to do the

jProgressBar update from SwingWorker

雨燕双飞 提交于 2019-11-26 20:40:15
问题 I use to monitor a long running task by updating a ProgressBar. The long running task is of course performed in a Swingworker thread. I used to program things like that : public class MySwingWorkerClass extends SwingWorker<Void, Void> { private JProgressBar progressBar; public MySwingWorker(JProgressBar aProgressBar) { this.progressBar = aProgressBar; progressBar.setVisible(true); progressBar.setStringPainted(true); progressBar.setValue(0); } @Override public Void doInBackground() { //long

java swingworker thread to update main Gui

血红的双手。 提交于 2019-11-26 19:10:07
hi id like to know whats the best way to add text to a jtextarea from a swingworkerthread, ive created another class which a jbutton calls by Threadsclass().execute(); and the thread runs in parallel fine with this code public class Threadsclass extends SwingWorker<Object, Object> { @Override protected Object doInBackground() throws Exception { for(int x = 0; x< 10;x++) try { System.out.println("sleep number :"+ x); Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(eftcespbillpaymentsThreads.class.getName()).log(Level.SEVERE, null, ex); } throw new

Execute process in Java without JFrame freezing

三世轮回 提交于 2019-11-26 18:40:33
问题 how can I execute a process in Java without the program freezing? I've tried using SwingWorker, but I don't quite yet understand how it works. Is there any other way I can accomplish this? I'm wanting to use something like this in my JDroidLib. For full source code, check out the GitHub: http://github.com/Team-M4gkBeatz/JDroidLib Thanks in advance! EDIT: Thanks for your answers. But I have a class with several methods (well, it's more than one class, but you get my point); how can I use a

Change Column Type of jtable when table populate from resultset

只谈情不闲聊 提交于 2019-11-26 18:38:40
问题 I have worker for fill the jtable from resultset like below; public class WorkerFillTable extends SwingWorker<DefaultTableModel, DefaultTableModel> { private DefaultTableModel modeltable; public WorkerFillTable(DefaultTableModel modeltable) { this.modeltable = modeltable; } @Override protected DefaultTableModel doInBackground() throws Exception { ResultSet rs; Statement stmt; String query = "select Name,ID,Status,IsActive from current_conf\n" + "order by Name,ID"; Class.forName("com.microsoft

How could I add a simple delay in a Java Swing application?

巧了我就是萌 提交于 2019-11-26 18:01:19
I'd like to know how to add a time delay inside a Swing app in Java, I used Thread.sleep(time) , and also I used SwingWorker but it doesn't work. Here's part of my code: switch (state) { case 'A': if (charAux == 'A') { state = 'B'; //Here's where I'd like to add a time delay jLabel13.setForeground(Color.red); break; } else { //Here's where I'd like to add a time delay jLabel12.setForeground(Color.red); break; } } I hope you could help me or solve my doubts when I'm using SwingWorker. Here's an example using a javax.swing.Timer public class TestBlinkingText { public static void main(String[]