Progress dialog

Sat Nov 27, 2010 10:32 pm

Following example show you how to create a dialog which contains , progress bar .Please take in mind that while your are waiting other processes is to use threads. For example you may want to run the main application process in a thread and the updating of the progress bar in other thread.

Code:

import java
.awt.BorderLayout;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.Border;

public class 
ProgressDialog extends JDialog {

    private final 
JPanel panel = new JPanel();
    private 
JProgressBar jProgressBar;
    private 
JLabel jLabel;

    public 
ProgressDialog(JFrame frameint initialString statusDescription) {
        
setTitle("Progress Dialog.");
        
jProgressBar = new JProgressBar();
        
jProgressBar.setString("In Progress ");
 

        
jProgressBar.setValue(25);
        
jProgressBar.setStringPainted(true);
        
Border border BorderFactory.createTitledBorder("Reading...");
        
jProgressBar.setBorder(border);

        
Point point frame.getLocation();
        
panel.add(jProgressBarBorderLayout.NORTH);
        
jLabel = new JLabel(statusDescription);
        
panel.add(jLabel);
        
add(panel);
         
        
setResizable(false);
        
setAlwaysOnTop(true);
        
setSize(300300);
        
setLocation((int) point.getX() + 100, (int) point.getY() + 100);

    }

    public 
void setPercentage(int percent) {
        
jProgressBar.setValue(percent);
    }
}
 




  Related Posts  to : Progress dialog
 java confirmation dialog     -  
 Show popup dialog using JQuery     -  
 status Progress bar     -  
 Show Progress Bar using JQuery     -  
 Multipart HTTP forms submitter - With Progress Information     -  

Topic Tags

Java Swing