List of usage examples for javax.swing JProgressBar isVisible
@Transient public boolean isVisible()
From source file:marytts.tools.voiceimport.DatabaseImportMain.java
/** * Run the selected components in a different thread. * *///from www. j a v a 2 s . c o m protected void runSelectedComponents() { new Thread("RunSelectedComponentsThread") { public void run() { try { runButton.setEnabled(false); for (int i = 0; i < components.length; i++) { if (checkboxes[i].isSelected()) { boolean success = false; Container parent = checkboxes[i].getParent(); final JProgressBar progress = new JProgressBar(); final VoiceImportComponent oneComponent = components[i]; if (oneComponent.getProgress() != -1) { progress.setStringPainted(true); new Thread("ProgressThread") { public void run() { int percent = 0; while (progress.isVisible()) { progress.setValue(percent); try { Thread.sleep(500); } catch (InterruptedException ie) { } percent = oneComponent.getProgress(); } } }.start(); } else { progress.setIndeterminate(true); } parent.add(progress, BorderLayout.EAST); progress.setVisible(true); parent.validate(); try { success = oneComponent.compute(); } catch (Exception exc) { checkboxes[i].setBackground(Color.RED); throw new Exception("The component " + checkboxes[i].getText() + " produced the following exception: ", exc); } finally { checkboxes[i].setSelected(false); progress.setVisible(false); } if (success) { checkboxes[i].setBackground(Color.GREEN); } else { checkboxes[i].setBackground(Color.RED); } } } } catch (Throwable e) { e.printStackTrace(); } finally { runButton.setEnabled(true); } } }.start(); }