Set all the values at once by using the model for JProgressBar in Java

Description

The following code shows how to set all the values at once by using the model for JProgressBar.

Example


  //  w w  w .  ja  va 2s.c  om
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JProgressBar;

public class Main extends JFrame {

  public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    int minimum = 0;
    int maximum = 100;
    JProgressBar progress = new JProgressBar(minimum, maximum);
    int newValue = 10;
    int newMin = 0;
    int newMax = 100;
    progress.getModel().setRangeProperties(newValue, 0, newMin, newMax, false);

    
    getContentPane().add(progress, BorderLayout.NORTH);
    pack();
    setVisible(true);
  }

  public static void main(String arg[]) {
    new Main();
  }
}

The code above generates the following result.

Set all the values at once by using the model for JProgressBar in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer