swingworker

Java Swing Threading with Updatable JProgressBar

淺唱寂寞╮ 提交于 2019-12-02 00:02:07
First off I've been working with Java's Concurrency package quite a bit lately but I have found an issue that I am stuck on. I want to have and Application and the Application can have a SplashScreen with a status bar and the loading of other data. So I decided to use SwingUtilities.invokeAndWait( call the splash component here ) . The SplashScreen then appears with a JProgressBar and runs a group of threads. But I can't seem to get a good handle on things. I've looked over SwingWorker and tried using it for this purpose but the thread just returns. Here is a bit of pseudo code. and the points

Preventing GUI From Freezing When Calling SwingWorker.get( )

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:14:04
问题 I have a program where I am loading a file while at the same time I am displaying a window to inform the user that the file is being loaded. I decided to make a FileLoader class that was a SwingWorker which actually handled loading the file and a ProgressWindow that implements PropertyChangeListener to inform the user about the status of the SwingWorker that was passed into it. My code currently looks like this: FileLoader loader = new FileLoader(filePath); new ProgressWindow(loader, "Loading

JTextArea not displaying text

不打扰是莪最后的温柔 提交于 2019-12-01 21:49:29
问题 In my function for displaying text in textarea,i have written following lines of code but it is not displaying any text jTextArea1.setText( Packet +"\n" +jTextArea1.getText()); I am using swingworker for performing background task,here is my code public class SaveTraffic extends SwingWorker<Void, Void> { public GUI f = new GUI(); @Override public Void doInBackground() throws IOException { //some code sendPacket(captor.getPacket().toString()); return null; }//end main function @Override public

Preventing GUI From Freezing When Calling SwingWorker.get( )

房东的猫 提交于 2019-12-01 20:41:10
I have a program where I am loading a file while at the same time I am displaying a window to inform the user that the file is being loaded. I decided to make a FileLoader class that was a SwingWorker which actually handled loading the file and a ProgressWindow that implements PropertyChangeListener to inform the user about the status of the SwingWorker that was passed into it. My code currently looks like this: FileLoader loader = new FileLoader(filePath); new ProgressWindow(loader, "Loading File", "Loading File"); //ProgressWindow's constructor calls loader.execute() inherited from

Is a swingWorker guaranteed to throw a state property change event on completion?

牧云@^-^@ 提交于 2019-12-01 19:41:20
问题 I have a class that takes in a number of SwingWorkers and runs them one at a time in a certain order. I use a ReentrantLock to make sure that only one worker runs at a time. Normally I would always unlock in a finally clause, but I need it to stay locked until the worker completes. nextWorker.getPropertyChangeSupport().addPropertyChangeListener("state", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue().equals(SwingWorker

updating a JProgressBar while processing

[亡魂溺海] 提交于 2019-12-01 19:25:29
I know the subject has already been seen on many Questions and has been answered, but still, I can't get trough it. I just want to update a progressBar while extracting some stuff of a large xml file. I thought it was enough to have the time-consuming loop in a different thread but ?.. All I managed to get is the progressBar either not showed at all, or updated at the end, just before it's closed. Instanced somewhere near the launch of the application, I have: public class SomeClass { private SomeClass () { myXMLParser reader = new myXMLParser(); CoolStuff fromXml = reader.readTheXml(); } }

setvisible method in java swing hangs system

别来无恙 提交于 2019-12-01 17:36:06
I have banking gui application that I am currently working on and there seems to be a problem with the setvisible method for my jdialog. After the user has withdrawn a valid amount I pop up a simple dialog that says "transaction in progress". In my dobackground method i keep polling to check if the transaction has been received. I tried using swingworker and I don't understand why it's not working. If i remove the setvisible call it works fine, so why does setvisible cause the system to hang? Here is the code that is inside my jbutton mouselistener: SwingWorker<String,Integer> worker = new

Java Swing multi threads and ui freezes

孤者浪人 提交于 2019-12-01 09:07:25
Can't figure this one out. Using worker or invokeLater, the UI still freeze. After each file is downloaded, I want a JList to be updated. But the JList will only update after the tread returns. Here is the code: public class MyUi extends javax.swing.JFrame{ ... private void jButton2ActionPerformed(java.awt.event.ActionEvent evt){ SwingUtilities.invokeLater(new Runnable() { //To get out of the event tread public void run() { dl(); } }); } private void dl(){ ... //ini and run the download class Download myDownload = new Download(); myDownload.doDownload(myDlList); } public void updateJlist

Java slideshow image delay using paintComponent

岁酱吖の 提交于 2019-12-01 07:41:31
I am putting together a slideshow program that will measure a user's time spent on each slide. The slideshow goes through several different magic tricks. Each trick is shown twice. Interim images are shown between the repetition. Transition images are shown between each trick. On the first repetition of a trick the JPanel color flashes on the screen after a click before the next image is shown. This doesn't happen during the second repetition of the same trick. It's possible that the image is taking too long to load. Is there an easy way to pre-load the images so that there isn't a delay the

Java Swing multi threads and ui freezes

心不动则不痛 提交于 2019-12-01 06:46:19
问题 Can't figure this one out. Using worker or invokeLater, the UI still freeze. After each file is downloaded, I want a JList to be updated. But the JList will only update after the tread returns. Here is the code: public class MyUi extends javax.swing.JFrame{ ... private void jButton2ActionPerformed(java.awt.event.ActionEvent evt){ SwingUtilities.invokeLater(new Runnable() { //To get out of the event tread public void run() { dl(); } }); } private void dl(){ ... //ini and run the download class