swingworker

How to Stop a SwingWorker?

谁说我不能喝 提交于 2019-12-24 03:32:29
问题 How can I stop the SwingWorker doing his work? I know there's the cancel() method for that, but the most I could do is to anonymously create a new SwingWorker that is doing the job. Here is the code for reference: public void mostrarResultado(final ResultSet resultado) { new SwingWorker<Void, Object[]>() { @Override public Void doInBackground() { // TODO: Process ResultSet and create Rows. Call publish() for every N rows created.+ DefaultTableModel modelo = new DefaultTableModel();

What threads are allowed to call SwingWorker#publish?

随声附和 提交于 2019-12-23 20:15:32
问题 Standard scenario: User presses button and starts big task. EventThread creates SwingWorker to execute the task and get's on with life. Now, since the big task is highly parallelizable, the first thing the SwingWorker thread does is to create a bunch of worker threads and farms the work out. My question: Are the worker threads allowed to call SwingWorker#publish() to trigger a GUI update or is only the SwingWorker thread allowed to do so? Thanks, Carsten [Edit] Some pseudo code to make my use

My JProgressBar is not Updating Until it is 100%

余生长醉 提交于 2019-12-23 12:53:47
问题 Ok, I have the following code. public class MyProgressBar extends JPanel implements MyData, Serializable { /** * */ public static final int MAX = 10000; public static final int WIDTH = 400; public static final int HEIGHT = 75; private JProgressBar MyBar = new JProgressBar( SwingConstants.HORIZONTAL, 0, MAX ); private JFrame MyFrame = new JFrame(); private int MyValue = 0; private Thread MyThread = new Thread( new ProgressThread() ); public MyProgressBar() { add(MyBar); int x = ( MyData.SCREEN

Swing components freezing until one component completes its job

喜夏-厌秋 提交于 2019-12-23 12:43:00
问题 I have created a simple JAVA Swing program that has a JTextArea, three JTextFields and one JButton. What this application does is when the user clicks the button it updates the JTextArea with a text line, the text line inserted into the JTextArea is prepared in a for loop and number of repeat times is given in a JTextField. My problem is when I click the start JButton all the components of the application are freeze, I can't even close the window until the for loop completes it's job. How can

How are the publish() and process() methods on SwingWorker properly used?

十年热恋 提交于 2019-12-22 07:23:06
问题 These two methods in SwingWorker are confusing me at the moment, and it seems like it is very easy to use them incorrectly. The method publish() describes the following: Sends data chunks to the process(java.util.List) method. This method is to be used from inside the doInBackground method to deliver intermediate results for processing on the Event Dispatch Thread inside the process method. What this means to me is that while my worker thread is executing its doInBackground() method, I am

java SwingWorker.doInBackground() must not access GUI elements

偶尔善良 提交于 2019-12-22 05:06:17
问题 May be this is trivial, I am struggling to understand a simple documentation on SwingWorker. Here is the copy pasted content Workflow There are three threads involved in the life cycle of a SwingWorker : Current thread: The execute() method is called on this thread. It schedules SwingWorker for the execution on a worker thread and returns immediately. One can wait for the SwingWorker to complete using the get methods. Worker thread: The doInBackground() method is called on this thread. This

SwingWorker exceptions lost even when using wrapper classes

孤街浪徒 提交于 2019-12-20 10:43:26
问题 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

update jlabel text after opening jdialog

我的未来我决定 提交于 2019-12-20 06:28:17
问题 I have to query database to get data to write on JLabel and to accelerate opening dialog I have created JLabel with no text and set text after done a SwingWorker process but JLabel text doesn't be updated Is there any way to achieve this Here is my dialog's src code: package com.caisse.caisseFrame.dialogs; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Image; import java.awt.Insets; import java.awt.event

java swing to count all controls

99封情书 提交于 2019-12-20 05:40:33
问题 How to count number of controls like JTextField, J Label and so on so..in java swing form designing,for example if we use only one textbox and one text field means i need the output as follows count value is 2.how to do this? 回答1: The container for the controls contains a list of controls, see Container.getComponents() . Come to think, it also has a method for the count of the controls, if that's all you want, Container.getComponentCount(). If you want this for all the controls contained

disposing frame from swingWorker

左心房为你撑大大i 提交于 2019-12-20 04:03:07
问题 actually i have called the swing worker from a frame (Suppose) A.. in the swing worker class in do-in-Background method i have certain db queries and i am calling frame B too.. in the done() method however i want to dispose the frame A.. how can i do that..? i cannot write dispose() in frame A class because that results in disposing of frame before the new frame(frame B) is visible... Please help!! class frameA extends JFrame{ public frameA(){ //done some operations.. SwingWorker worker=new