Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Set Bounds for JProgressBar in Java Swing
Use the setBounds() method to set Bounds for JProgressBar in Java Swing −
JProgressBar progressBar; progressBar.setBounds(70, 50, 120, 30);
The following is an example to set bounds for JProgressBar −
Example
package my;
import javax.swing.*;
public class SwingDemo extends JFrame {
JProgressBar progressBar;
int i = 0;
SwingDemo() {
progressBar = new JProgressBar(0, 1000);
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 displays a ProgessBar that fills completely −
Output

Advertisements
