swingworker

Prevent Swing GUI locking up during a background task

拟墨画扇 提交于 2019-11-26 05:38:00
问题 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,

How cancel the execution of a SwingWorker?

折月煮酒 提交于 2019-11-26 05:27:30
Currently I have two SwingWorker threads doing job on background. If an exception occurs, the method stop to work, but the thread still runnig. How I do to stop the execution and kill the thread of the doInBackground() if an exception occurs? this.cancel(true) don't destroy/close the thread. How can I achieve this? @Override protected Boolean doInBackground() throws Exception { try { while (true) { //some code here return true; } } catch (Exception e) { this.cancel(true); //<-- this not cancel the thread return false; } } I see these threads in the debug of Netbeans. 'AWT-EventQueue-0' em

Populate JTable with large number of rows

邮差的信 提交于 2019-11-26 04:54:31
问题 I would like to populate a JTable during runtime with many rows (lets say 10000). But all my attempts are very poor and inefficient. Starting point is the addData method which gets a List of Objects representing a row. I tried to fill the table via a SwingWorker but this only works for small data for me. Another attempt was setting the data directly without using any kind of thread, but this is also very slow, at least the UI isn\'t blocked like its the case with the SwingWorker. So how do

MVC Progress Bar Threading

江枫思渺然 提交于 2019-11-26 03:59:21
问题 I am using an MVC pattern for my design, when a user presses the search button, I call a search in the model, but I also want to update a progress bar with information returned from that model. I have tried using a swingworker, but the progress bar does not update. I suspect I am doing something wrong with my threading. My button as defined in the controller is: class SearchBtnListener implements ActionListener { public void actionPerformed(ActionEvent e) { _view.displayProgress(); } } This

Can a progress bar be used in a class outside main?

ⅰ亾dé卋堺 提交于 2019-11-26 01:18:07
问题 Right now, my main just calls a gui with 10 rows. Based on how many of those rows have text, 1 of 9 classes is called (two rows must have text). The called class performs calculations that I\'d like to have the progress bar tied to. Here is an example of one of the called classes (each class is similar, but different enough to warrant a new class.) I believe the problem is a violation of EDT rules, but all the examples I\'ve seen on them involve a main argument. The frame appears when the

How cancel the execution of a SwingWorker?

妖精的绣舞 提交于 2019-11-26 01:09:32
问题 Currently I have two SwingWorker threads doing job on background. If an exception occurs, the method stop to work, but the thread still runnig. How I do to stop the execution and kill the thread of the doInBackground() if an exception occurs? this.cancel(true) don\'t destroy/close the thread. How can I achieve this? @Override protected Boolean doInBackground() throws Exception { try { while (true) { //some code here return true; } } catch (Exception e) { this.cancel(true); //<-- this not

How to share data with two(2) SwingWorker class in Java

删除回忆录丶 提交于 2019-11-25 23:45:15
问题 I have two SwingWorker class: FileLineCounterThread and FileDivisionThread I will execute the two threads. When the lines counting thread finishes, it will pass the result to File Division thread. I do not have an idea on how to pass the result to started thread. 回答1: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener;

How do I use SwingWorker in Java?

不羁岁月 提交于 2019-11-25 23:16:48
问题 Related to my previous question: Call repaint from another class in Java? I\'m new to Java and I\'ve had a look at some tutorials on SwingWorker. Yet, I\'m unsure how to implement it with the example code I gave in the previous question. Can anyone please explain how to use SwingWorker with regards to my code snippet and/or point me towards a decent tutorial? I have looked but I\'m not sure I understand yet. 回答1: Generally, SwingWorker is used to perform long-running tasks in Swing. Running

Waiting for multiple SwingWorkers

爱⌒轻易说出口 提交于 2019-11-25 22:59:24
问题 Please consider the following code fragment: import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException; import javax.swing.*; public class TestApplet extends JApplet { @Override public void init() { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { createGUI(); } }); } catch(InterruptedException | InvocationTargetException ex) { } } private void createGUI() {

Can&#39;t get ArrayIndexOutOfBoundsException from Future<?> and SwingWorker if thread starts Executor

蓝咒 提交于 2019-11-25 22:00:16
问题 I play with multitreading for SwingWorker by using Executor, and I\'m there by mistake identified wrong elements from the Vector, looks like as this code pretty ignores that element in Vector doesn\'t exist my question -> how to/is possible to catch this exception(s) some way simple output run: Thread Status with Name :StartShedule, SwingWorker Status is STARTED Thread Status with Name :StartShedule, SwingWorker Status is DONE Thread Status with Name :StartShedule, SwingWorker Status is