swingworker

The proper way to handle exceptions thrown by the SwingWorker.doInBackground

陌路散爱 提交于 2020-01-07 05:32:13
问题 The proper way to handle exceptions thrown by the doInBackground method of SwingWorker class is to invoke the get method from within the done method, as explained here and here. The documentation for the get method states the following: Waits if necessary for the computation to complete, and then retrieves its result. Note: calling get on the Event Dispatch Thread blocks all events, including repaints, from being processed until this SwingWorker is complete. Therefore, if the get method

JAVA: JProgressbar & Files.copy With Observer and Swingworker in 1 Class

本秂侑毒 提交于 2020-01-07 03:52:11
问题 I wrote an aricle a couple months agoMY POST but I want to make some changes to I. Now all my code is worked out in the Swingworker class. But I want to use the MVC methode and use the observer pattern to update my variables in the view. Now i have something like this public class CopyFrame extends JFrame { private JTextarea textArea; private JProgresbar progresbar; public CopyFrame(){ progresbar = new JProgresbar textArea = new JTextarea(); progresbar.setMaximum(100)); /*in this method I

Updating the GUI in real time from SwingWorker

血红的双手。 提交于 2020-01-06 15:13:34
问题 Ok, this is a follow-up question to my question from yesterday, "Error handling in SwingWorker." In consideration of the fact that it might be ok to call SwingUtilities#invokeAndWait() inside of SwingWorker#doInBackground() , I want to push it a step further and ask: might it also be ok to call SwingUtilities#invokeLater() inside the background thread? Another SSCCE to illustrate: public class NewClass extends javax.swing.JFrame { public NewClass() { jScrollPane1 = new javax.swing.JScrollPane

How to structure publish() and process() in a SwingWorker to update more than one Swing component on the EDT?

佐手、 提交于 2020-01-06 14:59:11
问题 I have a ServerSocketChannel connection process in a SwingWorker. In the Swing application itself, two JLabels should update with (1) a String (connection status) and (2) an int (# of clients connected). Below is a screenshot of the application before "Detect Clients" JButton runs the connection process. However, I am not sure how to publish() and process() so as to update more than one Swing component on the EDT. Does anyone have guidance on how to achieve this? Because List<V> is the

Searching thousands of files via a thread and “tree walker”, writing matches to JTable results in unresponsiveness

六月ゝ 毕业季﹏ 提交于 2020-01-06 04:20:06
问题 I have revised my Windows 7 search program to write matched files to a JTable . Prior to this I was writing to a JTextArea . The output was ugly; hence JTable output. But with JTable , the program becomes unresponsive from time to time if searching thousands of files. (Not so with JTextArea . Very smooth.) My question is how to improve responsiveness. I have one Thread that is invoked in main and "walks the file tree" from a given node: public static void main(String args[]) { EventQueue

Searching thousands of files via a thread and “tree walker”, writing matches to JTable results in unresponsiveness

a 夏天 提交于 2020-01-06 04:19:07
问题 I have revised my Windows 7 search program to write matched files to a JTable . Prior to this I was writing to a JTextArea . The output was ugly; hence JTable output. But with JTable , the program becomes unresponsive from time to time if searching thousands of files. (Not so with JTextArea . Very smooth.) My question is how to improve responsiveness. I have one Thread that is invoked in main and "walks the file tree" from a given node: public static void main(String args[]) { EventQueue

How to update a progress bar from a method inside SwingWorker

前提是你 提交于 2020-01-05 12:31:34
问题 I'm trying to update a progress bar and I can't do it. My code is something like this: public class MyWorker extends SwingWorker<Void, Void> { public Void doInBackground(){ howMany=Integer.parseInt(textField.getText()); String result=longMethod(howMany); label.setText("Hello, you have "+result); } } public class Event implements ActionListener{ public void actionPerformed(ActionEvent e){ label2.setText("Whatever"); button.setEnabled(false); myWorer.addPropertyChangeListener(this); myWorker

How to update a progress bar from a method inside SwingWorker

北慕城南 提交于 2020-01-05 12:29:05
问题 I'm trying to update a progress bar and I can't do it. My code is something like this: public class MyWorker extends SwingWorker<Void, Void> { public Void doInBackground(){ howMany=Integer.parseInt(textField.getText()); String result=longMethod(howMany); label.setText("Hello, you have "+result); } } public class Event implements ActionListener{ public void actionPerformed(ActionEvent e){ label2.setText("Whatever"); button.setEnabled(false); myWorer.addPropertyChangeListener(this); myWorker

Java GUI Freezes even with SwingWorker

走远了吗. 提交于 2020-01-03 11:13:11
问题 I'm trying to use a SwingWorker to perform a lengthy task and update a JLabel with the result: button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new SwingWorker<String, Void>() { @Override protected String doInBackground() throws Exception { return doCalculation(); } protected void done() { try { label.setText(get()); } catch (InterruptedException e) { System.out.println("thread was interrupted"); } catch (ExecutionException e) { System

Java GUI Freezes even with SwingWorker

不问归期 提交于 2020-01-03 11:12:42
问题 I'm trying to use a SwingWorker to perform a lengthy task and update a JLabel with the result: button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { new SwingWorker<String, Void>() { @Override protected String doInBackground() throws Exception { return doCalculation(); } protected void done() { try { label.setText(get()); } catch (InterruptedException e) { System.out.println("thread was interrupted"); } catch (ExecutionException e) { System