List of usage examples for javax.swing JProgressBar setMinimum
@BeanProperty(bound = false, preferred = true, description = "The progress bar's minimum value.") public void setMinimum(int n)
n
. From source file:Main.java
public static void main(String[] argv) throws Exception { int minimum = 0; int maximum = 100; JProgressBar progress = new JProgressBar(minimum, maximum); // Get the current value int value = progress.getValue(); // Get the minimum value int min = progress.getMinimum(); // Get the maximum value int max = progress.getMaximum(); // Change the minimum value int newMin = 0; progress.setMinimum(newMin); // Change the maximum value int newMax = 256; progress.setMaximum(newMax);//w ww. j av a 2 s . c o m // Set the value; the new value will be forced into the bar's range int newValue = 33; progress.setValue(newValue); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
private static void installCallback(JFrame frame, File selected) { JDialog dialog = new JDialog(frame); JLabel status = new JLabel("Downloading build..."); JProgressBar progress = new JProgressBar(); dialog.pack();//w ww .j av a 2 s . c o m dialog.setVisible(true); try { URL url = new URL("http://download.redstonelamp.net/?file=LatestBuild"); InputStream is = url.openStream(); int size = is.available(); progress.setMinimum(0); progress.setMaximum(size); int size2 = size; OutputStream os = new FileOutputStream(new File(selected, "RedstoneLamp.jar")); while (size2 > 0) { int length = Math.min(4096, size2); byte[] buffer = new byte[length]; size2 -= length; is.read(buffer); progress.setValue(size2); os.write(buffer); } is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java
private static HeliosData loadHelios() throws IOException { System.out.println("Finding Helios implementation"); HeliosData data = new HeliosData(); boolean needsToDownload = !IMPL_FILE.exists(); if (!needsToDownload) { try (JarFile jarFile = new JarFile(IMPL_FILE)) { ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF"); if (entry == null) { needsToDownload = true;//from w ww. j a v a 2 s . c o m } else { Manifest manifest = new Manifest(jarFile.getInputStream(entry)); String ver = manifest.getMainAttributes().getValue("Implementation-Version"); try { data.buildNumber = Integer.parseInt(ver); data.version = manifest.getMainAttributes().getValue("Version"); data.mainClass = manifest.getMainAttributes().getValue("Main-Class"); } catch (NumberFormatException e) { needsToDownload = true; } } } catch (IOException e) { needsToDownload = true; } } if (needsToDownload) { URL latestJar = new URL(LATEST_JAR); System.out.println("Downloading latest Helios implementation"); FileOutputStream out = new FileOutputStream(IMPL_FILE); HttpURLConnection connection = (HttpURLConnection) latestJar.openConnection(); if (connection.getResponseCode() == 200) { int contentLength = connection.getContentLength(); if (contentLength > 0) { InputStream stream = connection.getInputStream(); byte[] buffer = new byte[1024]; int amnt; AtomicInteger total = new AtomicInteger(); AtomicBoolean stop = new AtomicBoolean(false); Thread progressBar = new Thread() { public void run() { JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JLabel label = new JLabel(); label.setText("Downloading latest Helios build"); panel.add(label); GridLayout layout = new GridLayout(); layout.setColumns(1); layout.setRows(3); panel.setLayout(layout); JProgressBar pbar = new JProgressBar(); pbar.setMinimum(0); pbar.setMaximum(100); panel.add(pbar); JTextArea textArea = new JTextArea(1, 3); textArea.setOpaque(false); textArea.setEditable(false); textArea.setText("Downloaded 00.00MB/00.00MB"); panel.add(textArea); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setContentPane(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); while (!stop.get()) { SwingUtilities.invokeLater( () -> pbar.setValue((int) (100.0 * total.get() / contentLength))); textArea.setText("Downloaded " + bytesToMeg(total.get()) + "MB/" + bytesToMeg(contentLength) + "MB"); try { Thread.sleep(100); } catch (InterruptedException ignored) { } } frame.dispose(); } }; progressBar.start(); while ((amnt = stream.read(buffer)) != -1) { out.write(buffer, 0, amnt); total.addAndGet(amnt); } stop.set(true); return loadHelios(); } else { throw new IOException("Content-Length set to " + connection.getContentLength()); } } else if (connection.getResponseCode() == 404) { // Most likely bootstrapper is out of date throw new RuntimeException("Bootstrapper out of date!"); } else { throw new IOException(connection.getResponseCode() + ": " + connection.getResponseMessage()); } } return data; }
From source file:Main.java
private JProgressBar makeProgressBar(int min, int max) { JProgressBar progressBar1 = new JProgressBar(); progressBar1.setMinimum(min); progressBar1.setMaximum(max);/*from w ww .j a va 2 s . c o m*/ progressBar1.setStringPainted(true); progressBar1.setBorderPainted(true); getContentPane().add(progressBar1); return progressBar1; }
From source file:com.roche.iceboar.progressview.ProgressUpdater.java
public ProgressUpdater(JProgressBar progressBar, JLabel messageLabel, ProgressEventFactory progressEventFactory) { this.progressBar = progressBar; this.messageLabel = messageLabel; this.events = new HashSet<ProgressEvent>(progressEventFactory.getAllProgressEvents()); amountOfEvents = events.size();//from w ww . j a va 2 s . co m progressBar.setMinimum(0); progressBar.setMaximum(amountOfEvents); progressBar.setValue(0); progressBar.setString("0 %"); }
From source file:com.ecrimebureau.File.Hash.java
public Hash(JInternalFrame jInternalFrame, JTextArea jTA, String alg, JProgressBar jProgressBar) { this.jTA = jTA; this.algorithim = alg; this.path = path; this.jProgressBar = jProgressBar; jProgressBar.setStringPainted(true); this.jInternalFrame = jInternalFrame; jProgressBar.setMinimum(0); jProgressBar.setValue(jProgressBar.getMinimum()); // }
From source file:com.moss.appprocs.swing.ProgressMonitorBean.java
private void update() { if (log.isDebugEnabled()) log.debug("Updating " + process.name()); ProgressReport report = process.progressReport(); super.getLabelTaskname().setText(process.name()); super.getLabelDescription().setText(process.description()); final JProgressBar pBar = getProgressBar(); String string = report.accept(new ProgressReportVisitor<String>() { public String visit(BasicProgressReport r) { getCommandButton().setEnabled(false); pBar.setIndeterminate(true); return r.describe() + "..."; }//from ww w . j a v a2s .c o m public String visit(TrackableProgressReport t) { pBar.setIndeterminate(false); pBar.setMinimum(0); pBar.setMaximum((int) t.length()); pBar.setValue((int) t.progress()); return t.describe(); } }); if (process.state() == State.STOPPABLE) { stopButton().setEnabled(true); } else { stopButton().setEnabled(false); } pBar.setString(string); }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * Installs the specified list of mods, updating the gui as it goes. * * @param mods The list of mods to install. * @param text The text area to update with logging statements. * @param progressBar The progress bar to update. */// w w w . j ava 2 s. co m public static void guiInstall(List<String> mods, JTextArea text, JProgressBar progressBar) { //Create backups to restore if the install fails. try { createBackup(); } catch (IOException e) { text.append("Failed to create backup copies of minecraft.jar and mods folder"); LOGGER.error("Failed to create backup copies of minecraft.jar and mods folder", e); return; } //Create a temp directory where we can unpack the jar and install mods. File tmp; try { tmp = getTempDir(); } catch (IOException e) { text.append("Error creating temp directory!"); LOGGER.error("Install Error", e); return; } if (!tmp.mkdirs()) { text.append("Error creating temp directory!"); return; } File mcDir = new File(InstallerConfig.getMinecraftFolder()); File mcJar = new File(InstallerConfig.getMinecraftJar()); File reqDir = new File(InstallerConfig.getRequiredModsFolder()); //Calculate the number of "tasks" for the progress bar. int reqMods = 0; for (File f : reqDir.listFiles()) { if (f.isDirectory()) { reqMods++; } } //3 "other" steps: unpack, repack, delete temp int baseTasks = 3; int taskSize = reqMods + mods.size() + baseTasks; progressBar.setMinimum(0); progressBar.setMaximum(taskSize); int task = 1; try { text.append("Unpacking minecraft.jar\n"); unpackMCJar(tmp, mcJar); progressBar.setValue(task++); text.append("Installing Core mods\n"); //TODO specific ordering required! for (File mod : reqDir.listFiles()) { if (!mod.isDirectory()) { continue; } String name = mod.getName(); text.append("...Installing " + name + "\n"); installMod(mod, tmp, mcDir); progressBar.setValue(task++); } if (!mods.isEmpty()) { text.append("Installing Extra mods\n"); //TODO specific ordering required! for (String name : mods) { File mod = new File(FilenameUtils .normalize(FilenameUtils.concat(InstallerConfig.getExtraModsFolder(), name))); text.append("...Installing " + name + "\n"); installMod(mod, tmp, mcDir); progressBar.setValue(task++); } } text.append("Repacking minecraft.jar\n"); repackMCJar(tmp, mcJar); progressBar.setValue(task++); } catch (Exception e) { text.append("!!!Error installing mods!!!"); LOGGER.error("Installation error", e); try { restoreBackup(); } catch (IOException ioe) { text.append("Error while restoring backup files minecraft.jar.backup and mods_backup folder\n!"); LOGGER.error("Error while restoring backup files minecraft.jar.backup and mods_backup folder!", ioe); } } text.append("Deleting temporary files\n"); try { FileUtils.deleteDirectory(tmp); progressBar.setValue(task++); } catch (IOException e) { text.append("Error deleting temporary files!\n"); LOGGER.error("Install Error", e); return; } text.append("Finished!"); }
From source file:bemap.TrackOrganiser.java
/** * Data treatment that has to be done after the import can be added here: * For instance://www . j av a2s . co m * Splits the imported tracks into several tracks after the import. */ public void postImportTreatment(JProgressBar progressBar) throws JSONException { BeMapEditor.mainWindow.append("\nTreatment..."); int indexOfImportedTrack = currentTrack.getID(); if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nImport track:" + indexOfImportedTrack); Data importTrack = currentTrack; int firstTrackID = currentTrack.getFirstTrackID(); int lastTrackID = currentTrack.getLastTrackID(); if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nFirst track: " + firstTrackID + " Last track: " + lastTrackID); progressBar.setMinimum(firstTrackID); progressBar.setMaximum(lastTrackID); for (int i = firstTrackID; i <= lastTrackID; i++) { progressBar.setValue(i); int nb = importTrack.getNumberOfPoints(i); if (nb >= MIN_NB_POINTS_IMPORT) { createNewTrack("Track " + i + "-" + BeMapEditor.mainWindow.getUsrIDofConnectedDevice()); if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nTrack " + i + " has " + nb + " points."); currentTrack.importJSONList(importTrack.exportJSONLayer(i)); } else if (TRACK_DEBUG) BeMapEditor.mainWindow.append("\nTrack " + i + " has " + nb + " points: No track created!"); } //delete import track deleteTrack(indexOfImportedTrack); BeMapEditor.mainWindow.append("\nTreatment ok!"); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java
/** * @param min// ww w . ja v a 2 s . c om * @param max * @param paintString - true if the progress bar should display string description of progress * @param itemName - string description will be: "itemName x of max" (using English resource). * * Initializes progress bar for upload actions. If min and max = 0, sets progress bar is * indeterminate. */ protected void initProgressBar(final int min, final int max, final boolean paintString, final String itemName, final boolean useAppProgress) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (!useAppStatBar && mainPanel == null) { log.error("UI does not exist."); return; } minProgVal = min; maxProgVal = max; indeterminateProgress = minProgVal == 0 && maxProgVal == 0; useAppStatBar = useAppProgress; if (useAppStatBar) { if (indeterminateProgress) { UIRegistry.getStatusBar().setIndeterminate("UPLOADER", indeterminateProgress); } else { UIRegistry.getStatusBar().setProgressRange("UPLOADER", minProgVal, maxProgVal); } } else { JProgressBar pb = mainPanel.getCurrOpProgress(); pb.setVisible(true); if (indeterminateProgress) { pb.setIndeterminate(true); pb.setString(""); } else { if (pb.isIndeterminate()) { pb.setIndeterminate(false); } pb.setStringPainted(paintString); if (paintString) { pb.setName(itemName); } pb.setMinimum(minProgVal); pb.setMaximum(maxProgVal); pb.setValue(minProgVal); } } } }); }