Note that there are some explanatory texts on larger screens.

plurals
  1. POJProgressBar indeterminate thread
    primarykey
    data
    text
    <p>I have a problem while creating a <code>JProgressBar</code> which is set to indeterminate. The following code is my implementation of the <code>JProgressBar</code> and is called/constructed from another class:</p> <pre><code>public class Progress implements Runnable { private JFrame frameProgress; private JProgressBar progressBar; public Progress(String title, String message) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { GlobalVariables.LOGGING_logger.error("Error instatiating progress bar.", e); } UIManager.put("ProgressBar.selectionForeground", Color.black); UIManager.put("ProgressBar.selectionBackground", Color.black); this.frameProgress = new JFrame(title); this.frameProgress.setIconImage(GlobalVariables.GUI_icon.getImage()); this.frameProgress.setSize(300, 60); this.frameProgress.setLocation(16, 16); this.progressBar = new JProgressBar(); this.progressBar.setStringPainted(true); this.progressBar.setString(message); this.progressBar.setIndeterminate(true); this.frameProgress.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.frameProgress.add(this.progressBar); this.frameProgress.setResizable(false); this.frameProgress.setVisible(true); } public void start() { new Thread(this).start(); } public void close() { this.frameProgress.dispose(); this.frameProgress = null; this.progressBar = null; } @Override public void run() { SwingUtilities.invokeLater(new Runnable() { public void run() { // do nothing, because progress bar is indeterminate } }); } } </code></pre> <p>The caller of this JProgressBar is the following code snippet:</p> <pre><code> Progress p = new Progress("bla", "blub"); p.start(); boolean successfull = xmlWriter.writeCommonSettingsFromGUI(this); p.close(); </code></pre> <p>And now i want, while the <code>xmlWriter.writeCommonSettingsFromGUI(this);</code> is doing something, that the <code>JProgressBar</code> is shown to the user and is working while the algorithm is running.</p> <p>How can I achieve this? I don't know so much about threading and searched in many other forums, but I don't found any answer for my question.</p> <p>Please help me and thank you in advance ;)</p> <p>EDIT: The Progress JFrame opens up with no content for that time, the algorithm is running.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload