- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- How to set the maximized bounds for a Frame in Java?
- How to set fullscreen mode for Java Swing Application?
- How to set all the values at once using the model in a JProgressBar with Java?
- How to set a different look and feels to swing components in Java?
- Create translucent windows in Java Swing
- Create Toast Message in Java Swing
- Create shaped windows in Java Swing
- Is Swing thread-safe in Java?
- Explain the architecture of Java Swing in Java?
- Create gradient translucent windows in Java Swing
- How to maximize JFrame in Java Swing
- How to make a canvas in Java Swing?
- Java Program to create rounded borders in Swing
- How to change Button Border in Java Swing
- How to handle Java Array Index Out of Bounds Exception?

Advertisements