

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set all the values at once using the model in a JProgressBar with Java?
The getModel() method is used to set all the values at once for a JProgressBar −
int newVal = 5; int newMin = 0; int newMax = 100; progressBar.getModel().setRangeProperties(newVal, 0, newMin, newMax, true);
The following is an example to set all the values at once using the model in a progress bar −
Example
package my; import javax.swing.*; public class SwingDemo extends JFrame { JProgressBar progressBar; int i = 0; SwingDemo() { int min = 0; int max = 1000; progressBar = new JProgressBar(min, max); int newVal = 5; int newMin = 0; int newMax = 100; progressBar.getModel().setRangeProperties(newVal, 0, newMin, newMax, true); progressBar.setBounds(70, 50, 120, 30); progressBar.setValue(0); progressBar.setStringPainted(true); add(progressBar); setSize(550, 150); setLayout(null); } public void inc() { while (i <= 1000) { progressBar.setValue(i); i = i + 50; try { Thread.sleep(100); } catch (Exception e) {} } } public static void main(String[] args) { SwingDemo s = new SwingDemo(); s.setVisible(true); s.inc(); } }
The output is as follows. The Progress Bar is displaying −
The Progress Bar completely visible now −
- Related Questions & Answers
- How to set all the four border radius properties at once with JavaScript?
- How to close all Android activities at once using Kotlin?
- Set Bounds for JProgressBar in Java Swing
- How to close all activities at once in android?
- C# Program to read all the lines of a file at once
- How to download all images on a web page at once?
- Saving all the open Matplotlib figures in one file at once
- How to set all the Arrow Buttons in a frame with Java?
- Java Program to retrieve the set of all values in HashMap
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?
- How can we get the values of a JProgressBar Component and display in Console?
- Java Program to retrieve the set of all keys and values in HashMap
- How to set the chart title at the bottom using ggplot2 in R?
- How to get all the values in a worksheet in Selenium with python?
- Selecting all the users with maximum age values using a MySQL subquery?
Advertisements