swingworker

JPanel with a specific JRadioButton does not update after getting result from SwingWorker thread

喜夏-厌秋 提交于 2020-01-16 06:31:27
问题 I am making a Java GUI application. For reading two types of files required as an input, I am using the SwingWorker class which performs the operation in two different background threads. Once, the two types of files are read, there are a lot of components which get updated in the GUI with data and a HeatMap in one of the JPanel . This JPanel contains two JRadioButton , which on switching should display the two different heat maps obtained from the two files read by the application. I can see

Tracking progress of multiple image downloads with SwingWorker and JProgressBar

假装没事ソ 提交于 2020-01-16 04:28:11
问题 I'm having a hard time figuring out the right way to use SwingWorker to track multiple image downloads. I'm writing a GUI program that takes a list of image URLs as input, reads each image, and uses PDFBox to save all the images as a single PDF file. I have a downloader class with the following method: public void downloadImagesAsPDF(URL[] urlList, String filename){ if(urlList.length == 0) return; //build pdf try { PDDocument doc = new PDDocument(); for(URL imgLink : urllist){ try{

Progress bar freezing while downloading file in java [duplicate]

别来无恙 提交于 2020-01-15 06:08:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: JProgressBar wont update So I am trying to show the download progress of a file being downloaded in Java. I can output the current percentage as a String to the console, but when I try to update the UI, it freezes until the download is complete. public void downloadFile(String fileName) { try { long startTime = System.currentTimeMillis(); System.out.println("Connecting to site...\n"); URL url = new URL("http:/

Catch Exception thrown by a SwingWorker located in a different class

岁酱吖の 提交于 2020-01-14 14:21:29
问题 I have a main class Gui that handles my GUI and calls a few SwingWorkers (calls to DB and other data sources) that have been put in their own class TablesDataManager . My issue is that when one of those swingworkers throws an exception within its done90 method (i.e. on the EDT), I want to be able to catch it somehow in the main class and act accordingly (call showErrorAndExit in my SSCCE below). Any ideas would be welcome. Gui.java import java.awt.event.WindowEvent; import javax.swing.*;

Using SwingWorker to update the progress of a thread from another class

ぃ、小莉子 提交于 2020-01-14 05:27:50
问题 Value is updated by the end, but not during the process. I guess the reason is that the publish method locates outside the loop. As to invoke PropertyChangeListener , can it be achieved by defining the class without extends SwingWorker<Void, Void> ? To address the question in another way, I have two threads locate in two different classes. Is it possible to build communication between the two using SwingWorker ? Class Application import javax.swing.JFrame; public class Application { public

Error handling in SwingWorker

别来无恙 提交于 2020-01-11 08:54:29
问题 My question is a theory-based question, but it does meet a specific need I have. What do you do when your SwingWorker throws an Exception that you a) can anticipate and b) need to recover from and continue, but you want to notify the user that this error has happened? How do you grab the expected exception and notify the user without violating the "No Swing code from doInBackground() " rule? I have, in consideration of this problem, developed a SSCCE that I would like to put forth with the

Safely open and close modal JDialog (using SwingWorker)

吃可爱长大的小学妹 提交于 2020-01-10 05:04:02
问题 I needed a way to get some data from a database and prevent the user from modifying existing data for that moment. I created a SwingWorker to make the db update and a modal JDialog to show user what is going on (with a JProgressBar). The modal dialog has defaultCloseOperation set to DO_NOTHING, so it can only be closed with a proper call - I use setVisible(false) . MySwingWorkerTask myTask = new MySwingWorkerTask(); myTask.execute(); myModalDialog.setVisible(true); The SwingWorker does some

Safely open and close modal JDialog (using SwingWorker)

旧时模样 提交于 2020-01-10 05:03:05
问题 I needed a way to get some data from a database and prevent the user from modifying existing data for that moment. I created a SwingWorker to make the db update and a modal JDialog to show user what is going on (with a JProgressBar). The modal dialog has defaultCloseOperation set to DO_NOTHING, so it can only be closed with a proper call - I use setVisible(false) . MySwingWorkerTask myTask = new MySwingWorkerTask(); myTask.execute(); myModalDialog.setVisible(true); The SwingWorker does some

Why is SwingWorker not returning an object to the EDT?

烂漫一生 提交于 2020-01-07 08:24:30
问题 I am using the SwingWorker class to perform a background task. Many different components of the GUI get updated after the background thread has done is job (these are in the done() method). The doInBackground() method publishes a HeatMap class object and the process() method adds it to a JPanel component. I have added MouseListener and MouseMotionListener to this Heatmap class object. The mouseMoved() method is present in the main GUI class. When the mouse is moved, the coordinate position of

Why is SwingWorker not returning an object to the EDT?

岁酱吖の 提交于 2020-01-07 08:24:01
问题 I am using the SwingWorker class to perform a background task. Many different components of the GUI get updated after the background thread has done is job (these are in the done() method). The doInBackground() method publishes a HeatMap class object and the process() method adds it to a JPanel component. I have added MouseListener and MouseMotionListener to this Heatmap class object. The mouseMoved() method is present in the main GUI class. When the mouse is moved, the coordinate position of