LazzyIzzi got tired of writing the same JProgressBar code over and over
The ProgressBars class wraps the methods of the JProgressBar class.
import java.awt.Color; import java.util.ArrayList; import javax.swing.JProgressBar; import ij.IJ; import ij.plugin.PlugIn; import jhd.ProgressBars.*; public class Test_ProgressBars implements PlugIn { final Color myColor = new Color(240,230,190);//slightly darker than buff @Override public void run(String arg) { //ProgressBars(java.lang.String windowTitle) ProgressBars progBars = new ProgressBars("Progress Bars Example"); //add(java.lang.String progBarTitle, int progressbarWidth, int progressbarHeight, int minBarValue, int maxBarValue) progBars.add("Main Process", 350, 20, 0, 1); progBars.add("Sub Process", 350, 20, 0, 1); progBars.add("Wrap Up", 350, 20, 0, 1); progBars.setBackground(myColor); progBars.show(); //public void setMaxBarValue(java.lang.String name, int value) progBars.setMaxBarValue("Main Process", 20); progBars.setMaxBarValue("Sub Process", 200); progBars.setMaxBarValue("Wrap Up", 200); //Example "get" calls, not required, values will appear in the ImageJ Log window ArrayList<JProgressBar> pbList = progBars.getProgBars(); for(JProgressBar pb : pbList) { IJ.log(pb.getName() + ", "+ pb.getMaximum()); } JProgressBar[] pbArr = progBars.getProgBarsAsArray(); for(JProgressBar pb : pbArr) { IJ.log(pb.getName() + ", "+ pb.getMaximum()); } // running the example processes (simple loops) and updating the appropriate progress bars //setValue(java.lang.String name, int value) for(int j=0;j<=20;j++) { for(int i=0;i<=200;i++) { progBars.setValue("Sub Process",i); IJ.wait(5); } progBars.setValue("Main Process",j); } for(int i=0;i<=200;i++) { progBars.setValue("Wrap Up",i); IJ.wait(5); } progBars.close(); } }
import jhd.ProgressBars.*; import java.awt.Color; //import java.util.ArrayList; //uncomment to use arraylst code import javax.swing.JProgressBar; public class testProgBars { public static void main(String[] args) { final Color myColor = new Color(240,230,190);//slightly darker than buff ProgressBars progBars = new ProgressBars("Progress Bars Example"); progBars.add("Main Process", 350, 20, 0, 1); progBars.add("Sub Process", 350, 20, 0, 1); progBars.add("Wrap Up", 350, 20, 0, 1); progBars.setBackground(myColor); progBars.show(); progBars.setMaxBarValue("Main Process", 20); progBars.setMaxBarValue("Sub Process", 200); progBars.setMaxBarValue("Wrap Up", 200); //uncomment to use arraylst code // ArrayList<JProgressBar> pbList = progBars.getProgBars(); // for(JProgressBar pb : pbList) // { // System.out.println(pb.getName() + ", "+ pb.getMaximum()); // } JProgressBar[] pbArr = progBars.getProgBarsAsArray(); for(JProgressBar pb : pbArr) { System.out.println(pb.getName() + ", "+ pb.getMaximum()); } for(int j=0;j<=20;j++) { for(int i=0;i<=200;i++) { progBars.setValue("Sub Process",i); try {Thread.sleep(5);} catch (InterruptedException e) { } } progBars.setValue("Main Process",j); } for(int i=0;i<=200;i++) { progBars.setValue("Wrap Up",i); try {Thread.sleep(5);} catch (InterruptedException e) { } } progBars.close(); } }