Java Code Examples for javax.swing.JProgressBar#setValue()

The following examples show how to use javax.swing.JProgressBar#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoUpgrade.java    From netbeans with Apache License 2.0 8 votes vote down vote up
private static boolean showUpgradeDialog (final File source, String note) {
       Util.setDefaultLookAndFeel();

JPanel panel = new JPanel(new BorderLayout());
panel.add(new AutoUpgradePanel (source.getAbsolutePath (), note), BorderLayout.CENTER);
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
panel.add(progressBar, BorderLayout.SOUTH);
progressBar.setVisible(false);

JButton bYES = new JButton("Yes");
bYES.setMnemonic(KeyEvent.VK_Y);
JButton bNO = new JButton("No");
bNO.setMnemonic(KeyEvent.VK_N);
JButton[] options = new JButton[] {bYES, bNO};
       JOptionPane p = new JOptionPane (panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, bYES);
       JDialog d = Util.createJOptionProgressDialog(p, NbBundle.getMessage (AutoUpgrade.class, "MSG_Confirmation_Title"), source, progressBar);
       d.setVisible (true);

       return new Integer (JOptionPane.YES_OPTION).equals (p.getValue ());
   }
 
Example 2
Source File: CharacterDialog.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
private void createSkillBlock(SkillProperty skillProperty, JPanel parentPanel, int x, int y) {
	
	String skillDescription = skillProperty.getName();
	skillDescription = Character.toUpperCase(skillDescription.charAt(0)) + skillDescription.substring(1);
	JLabel lblSkill = JLabelFactory.createJLabel(skillDescription);
	lblSkill.setBounds(x, y, 110, 20);
	lblSkill.setToolTipText(skillProperty.getLongDescription());
	parentPanel.add(lblSkill);
	
	JLabel lblSkillValue = JLabelFactory.createJLabel(playerCharacter.getProperty(skillProperty).toString());
	lblSkillValue.setBounds(x + 115, y, 15, 20);
	lblSkillValue.setToolTipText(skillProperty.getLongDescription());
	parentPanel.add(lblSkillValue);
	
	JProgressBar skillProgressBar = JProgressBarFactory.createHorizontalJProgressBar(0, 100, imageInfoReader);
	skillProgressBar.setBounds(x + 130, y, 130, 20);
	skillProgressBar.setToolTipText(skillProperty.getLongDescription());
	skillProgressBar.setValue(playerCharacter.getProperty(skillProperty).getPercentageUntilNextLevelUp());
	parentPanel.add(skillProgressBar);
}
 
Example 3
Source File: ProgressBarMemoryLeakTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void showUI(){
  sFrame = new JFrame();

  JProgressBar progressBar = new JProgressBar();
  progressBar.setVisible(false);
  progressBar.setIndeterminate(false);
  progressBar.setIndeterminate(true);
  progressBar.setIndeterminate(false);
  progressBar.setValue(10);
  progressBar.setString("Progress");

  sFrame.add(progressBar);

  sProgressBar = new WeakReference<>(progressBar);

  sFrame.setSize(200,200);
  sFrame.setVisible(true);
}
 
Example 4
Source File: ProgressDialog.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void init( ProgressMonitor monitor ) {
    this.monitor = monitor;

    progressBar = new JProgressBar(0, monitor.getTotal());
    if (monitor.isIndeterminate())
        progressBar.setIndeterminate(true);
    else
        progressBar.setValue(monitor.getCurrent());
    statusLabel.setText(monitor.getStatus());

    JPanel contents = (JPanel) getContentPane();
    contents.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    contents.add(statusLabel, BorderLayout.NORTH);
    contents.add(progressBar);

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    monitor.addChangeListener(this);
}
 
Example 5
Source File: ProgressBarMemoryLeakTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void showUI(){
  sFrame = new JFrame();

  JProgressBar progressBar = new JProgressBar();
  progressBar.setVisible(false);
  progressBar.setIndeterminate(false);
  progressBar.setIndeterminate(true);
  progressBar.setIndeterminate(false);
  progressBar.setValue(10);
  progressBar.setString("Progress");

  sFrame.add(progressBar);

  sProgressBar = new WeakReference<>(progressBar);

  sFrame.setSize(200,200);
  sFrame.setVisible(true);
}
 
Example 6
Source File: ProgressBarMemoryLeakTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void showUI(){
  sFrame = new JFrame();

  JProgressBar progressBar = new JProgressBar();
  progressBar.setVisible(false);
  progressBar.setIndeterminate(false);
  progressBar.setIndeterminate(true);
  progressBar.setIndeterminate(false);
  progressBar.setValue(10);
  progressBar.setString("Progress");

  sFrame.add(progressBar);

  sProgressBar = new WeakReference<>(progressBar);

  sFrame.setSize(200,200);
  sFrame.setVisible(true);
}
 
Example 7
Source File: PanelNav.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private void initialize() {
    this.setLayout(new GridLayout(2, 0, 0, 0)); // -Create a two column grid

    progressBar = new JProgressBar(); // -Create, initialize and setup a progress bar
    progressBar.setValue((100 / cardCount));
    this.add(progressBar); // -Positions the progress bar into the top column
    JPanel navBar = new JPanel(); // -Create a two row grid for navigation buttons
    this.add(navBar);
    navBar.setLayout(new GridLayout(0, 2, 0, 0));

    btnBack =
            new JButton(
                    Constant.messages.getString(
                            "exportreport.previous.back.label")); // -Create the back button and
    // place it into the left row
    btnBack.setEnabled(false);
    navBar.add(btnBack);

    btnNext =
            new JButton(
                    Constant.messages.getString(
                            "exportreport.forward.next.label")); // -Create the next button and
    // place it into the right row
    navBar.add(btnNext);
}
 
Example 8
Source File: ProgressBarMemoryLeakTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void showUI(){
  sFrame = new JFrame();

  JProgressBar progressBar = new JProgressBar();
  progressBar.setVisible(false);
  progressBar.setIndeterminate(false);
  progressBar.setIndeterminate(true);
  progressBar.setIndeterminate(false);
  progressBar.setValue(10);
  progressBar.setString("Progress");

  sFrame.add(progressBar);

  sProgressBar = new WeakReference<>(progressBar);

  sFrame.setSize(200,200);
  sFrame.setVisible(true);
}
 
Example 9
Source File: StartupPanel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Create a new instance of StartupPanel
 * @param gameModeFileLoader
 * @param campaignFileLoader
 */
public StartupPanel(GameModeFileLoader gameModeFileLoader, CampaignFileLoader campaignFileLoader)
{
	this.gameModeFileLoader = gameModeFileLoader;
	this.campaignFileLoader = campaignFileLoader;
	message = new JPanel();
	message.setLayout(new UnstretchingGridLayout(0, 1));
	message
		.add(new JLabel("Welcome to the PCGen " + PCGenPropBundle.getProdVersionSeries() + " Data Converter..."));
	message.add(new JLabel(" "));
	message.add(new JLabel("Loading Game Modes and Campaign Information."));
	message.add(new JLabel(" "));

	progressBar = new JProgressBar(0, 3);
	progressBar.setValue(0);
	progressBar.setStringPainted(true);

	message.add(progressBar);
	message.add(new JLabel(" "));
}
 
Example 10
Source File: BaselineCorrectorSetupDialog.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void addProgessBar() {
  // Add progress bar
  progressBar = new JProgressBar();
  progressBar.setValue(25);
  progressBar.setStringPainted(true);
  Border border =
      BorderFactory.createTitledBorder("Processing...     <Press \"ESC\" to cancel>    ");
  progressBar.setBorder(border);
  this.dialog.add(progressBar, BorderLayout.NORTH);
  // this.dialog.repaint();
  progressBar.setVisible(true);
  this.dialog.pack();
}
 
Example 11
Source File: GenericProgressDialog.java    From GpsPrune with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the dialog to show the progress
 */
private void createProgressDialog()
{
	_progressDialog = new JDialog(_parentFrame, I18nManager.getText(_dialogTitleKey));
	_progressDialog.setLocationRelativeTo(_parentFrame);
	_progressBar = new JProgressBar(0, 100);
	_progressBar.setValue(0);
	_progressBar.setStringPainted(true);
	_progressBar.setString("");
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
	panel.add(new JLabel(I18nManager.getText(_labelKey)));
	panel.add(_progressBar);
	panel.add(Box.createVerticalStrut(6)); // spacer
	JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
	cancelButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
		{
			_function.cancel();
		}
	});
	panel.add(cancelButton);
	_progressDialog.getContentPane().add(panel);
	_progressDialog.pack();
	_progressDialog.setVisible(true);
}
 
Example 12
Source File: ExecutorProgressGui.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public ExecutorProgressGui( int max ) {
    frame = new JFrame();
    JLabel label = new JLabel("Loading...");
    JProgressBar jpb = new JProgressBar(0, max);
    jpb.setIndeterminate(false);
    JPanel panel = new JPanel(new BorderLayout(10, 10));
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    panel.add(label, BorderLayout.NORTH);
    panel.add(jpb, BorderLayout.CENTER);
    frame.add(panel);
    frame.pack();
    frame.setSize(w, h);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setIconImage(ImageCache.getBuffered(ImageCache.HORTONMACHINE_FRAME_ICON));
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    progress = new IProgressPrinter(){
        @Override
        public void publish( ProgressUpdate update ) {
            if (update.errorMessage != null) {
                frame.dispose();
                GuiUtilities.showErrorMessage(panel, update.errorMessage);
            } else {
                label.setText(update.updateString);
                jpb.setValue(update.workDone);
            }
        }

        @Override
        public void done() {
            if (frame != null && frame.isVisible())
                frame.dispose();
        }
    };
}
 
Example 13
Source File: TimerFrame.java    From training with MIT License 5 votes vote down vote up
public TimerFrame() {
	setUndecorated(true);
	getContentPane().setBackground(Color.lightGray);
	setShape(new RoundRectangle2D.Double(0, -20, GlobalSettings.WIDTH/2, 44, 20, 20));
	setSize(GlobalSettings.WIDTH/2, 24);
	setLocation(getX(), 0);
	horizontalPositioner.tick();
	setAlwaysOnTop(true);
	setFocusable(false);
	setType(Type.UTILITY);
	setFocusableWindowState(false);

	getContentPane().setLayout(new BorderLayout());
	
	progressBar = new JProgressBar();
	progressBar.setForeground(Color.lightGray);
	progressBar.setBackground(Color.GREEN);
	progressBar.setString("1 min");
	progressBar.setStringPainted(true);
	progressBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
	progressBar.setBorderPainted(false);
	progressBar.setValue(50);
	progressBar.setFont(new Font("Consolas", Font.BOLD, 19));
	progressBar.addMouseListener(new ProgressMouseListener());
	progressBar.setCursor(new Cursor(Cursor.HAND_CURSOR));
	getContentPane().add(progressBar);
}
 
Example 14
Source File: ProgressDialog.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 * 
 * @param progressBar The progress bar this has to update
 */
public ProgressDialog(Window parent, String dialogTitle) {
	super(parent, dialogTitle, ModalityType.APPLICATION_MODAL);

	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	setResizable(false);

	bundle = java.util.ResourceBundle.getBundle("course_generator/Bundle");
	Container paneGlobal = getContentPane();
	paneGlobal.setLayout(new GridBagLayout());

	// -- Progress bar
	progressBar = new JProgressBar(0, 100);
	progressBar.setValue(0);
	progressBar.setStringPainted(true);
	progressBar.setPreferredSize(new Dimension(500, 30));
	Utils.addComponent(paneGlobal, progressBar, 0, 0, 1, 1, 0, 0, 10, 10, 10, 10,
			GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

	// -- Cancel button
	buttonCancel = new JButton(bundle.getString("Global.btCancel.text"));
	buttonCancel.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			if (progressDialogListener != null) {
				progressDialogListener.progressDialogCancelled();
			}

		}
	});
	Utils.addComponent(paneGlobal, buttonCancel, 0, 1, 1, 1, 0, 0, 0, 10, 10, 10, GridBagConstraints.CENTER,
			GridBagConstraints.NONE);

	pack();
	// -- Center the dialog on the parent
	setLocationRelativeTo(parent);
}
 
Example 15
Source File: ProgressPanel.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
private void setProgressValues (JProgressBar pb, JLabel lbl, double value, String msg)
{
	if (!pb.isVisible())
		return ;
	int pbVal = Math.min((int) (value * 100), 100) ;
	if (pb.isIndeterminate())
		pb.setIndeterminate(false) ;
	pb.setValue(pbVal);
	lbl.setText((msg == null)?(""):(msg)); 	
}
 
Example 16
Source File: UpdateProgressBar.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
private void initializeComponents() {
	JPanel contentPane = (JPanel) this.getContentPane();

	contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
	contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

	if (fromVersion == null) {
		contentPane.add(new JLabel("Please wait while " + ClientGameConfiguration.get("GAME_NAME") + " is downloaded..."));
	} else {
		contentPane.add(new JLabel("Downloading updates..."));
	}
	contentPane.add(Box.createVerticalStrut(5));

	progressBar = new JProgressBar(0, max);
	progressBar.setStringPainted(false);
	progressBar.setValue(0);
	contentPane.add(progressBar);
	contentPane.add(Box.createVerticalStrut(5));

	if (urlBase != null) {
		// Set up page display.
		browser = new JEditorPane();
		browser.setContentType("text/html");
		browser.setEditable(false);
		Dimension dim = new Dimension(600, 440);
		browser.setPreferredSize(dim);
		browser.addPropertyChangeListener("page", new UpdateProgressBarMetaRefreshSupport());
		browser.addHyperlinkListener(new UpdateProgressBarHyperLinkListener());

		Dimension windowSize = new Dimension(640, 480);
		setPreferredSize(windowSize);
		// TODO: load page async?
		try {
			browser.setPage(urlBase + fromVersion + "/" + toVersion + ".html");
		} catch (IOException e) {
			System.out.println(e);
		}

		// Gige the page scroll bars if it needs them
		final JScrollPane scrollPane = new JScrollPane(browser);
		contentPane.add(scrollPane);
	}
}
 
Example 17
Source File: DownloadDialog.java    From LoboBrowser with MIT License 4 votes vote down vote up
private void updateProgress(final ProgressType progressType, final int value, final int max) {
  final String sizeText = getSizeText(value);
  this.transferSizeField.setValue(sizeText);

  final long newTimestamp = System.currentTimeMillis();
  final double lastTransferRate = this.lastTransferRate;
  final long lastProgressValue = this.lastProgressValue;
  final long lastTimestamp = this.lastTimestamp;
  final long elapsed = newTimestamp - lastTimestamp;
  double newTransferRate = Double.NaN;
  if (elapsed > 0) {
    newTransferRate = (value - lastProgressValue) / elapsed;
    if (!Double.isNaN(lastTransferRate)) {
      // Weighed average
      newTransferRate = (newTransferRate + (lastTransferRate * 5.0)) / 6.0;
    }
  }
  if (!Double.isNaN(newTransferRate)) {
    this.transferRateField.setValue(round1(newTransferRate) + " Kb/sec");
    final int cl = this.knownContentLength;
    if ((cl > 0) && (newTransferRate > 0)) {
      this.timeLeftField.setValue(Timing.getElapsedText((long) ((cl - value) / newTransferRate)));
    }
  }
  this.lastTimestamp = newTimestamp;
  this.lastProgressValue = value;
  this.lastTransferRate = newTransferRate;

  final JProgressBar pb = this.progressBar;
  if (progressType == ProgressType.CONNECTING) {
    pb.setIndeterminate(true);
    pb.setStringPainted(true);
    pb.setString("Connecting...");
    this.setTitle(this.destinationField.getValue() + ": Connecting...");
  } else if (max <= 0) {
    pb.setIndeterminate(true);
    pb.setStringPainted(false);
    this.setTitle(sizeText + " " + this.destinationField.getValue());
  } else {
    final int percent = (value * 100) / max;
    pb.setIndeterminate(false);
    pb.setStringPainted(true);
    pb.setMaximum(max);
    pb.setValue(value);
    final String percentText = percent + "%";
    pb.setString(percentText);
    this.setTitle(percentText + " " + this.destinationField.getValue());
  }
}
 
Example 18
Source File: MavenDownloader.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
public static void downloadFully(URL url, File target, JProgressBar progressBar) throws IOException {

        // We don't use the settings here explicitly, since HttpRequests picks up the network settings from studio directly.
        try {
            URLConnection connection = url.openConnection();
            if (connection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) connection).setInstanceFollowRedirects(true);
                ((HttpsURLConnection) connection).setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)");
                ((HttpsURLConnection) connection).setRequestProperty("Accept-Charset", "UTF-8");
                ((HttpsURLConnection) connection).setDoOutput(true);
                ((HttpsURLConnection) connection).setDoInput(true);
            }
            connection.setConnectTimeout(3000);
            connection.connect();
            int contentLength = connection.getContentLength();
            if (contentLength < 1) {
                throw new FileNotFoundException();
            }
            if (progressBar != null) {
                progressBar.setMinimum(0);
                progressBar.setMaximum(contentLength);
            }
            OutputStream dest = new FileOutputStream(target);
            InputStream in = connection.getInputStream();
            int count;
            int done = 0;
            byte data[] = new byte[BUFFER_SIZE];
            while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
                done += count;
                if (progressBar != null) {
                    progressBar.setValue(done);
                }
                dest.write(data, 0, count);
            }
            dest.close();
            in.close();
        } finally {
            if (target.length() == 0) {
                try {
                    target.delete();
                } catch (Exception e) {
                }
            }
        }
    }
 
Example 19
Source File: ProgressPanel.java    From swift-explorer with Apache License 2.0 4 votes vote down vote up
private final void done (JProgressBar progressBar, JLabel progressLabel)
{
	progressBar.setValue(100);
}
 
Example 20
Source File: ProgressPanel.java    From swift-explorer with Apache License 2.0 4 votes vote down vote up
private final void start (JProgressBar progressBar, JLabel progressLabel)
{
	progressBar.setValue(0);
	progressLabel.setText("Processing");
    progressBar.setIndeterminate(true) ;
}