test class:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test extends JFrame implements ActionListener{
progressBar bar = new progressBar();
JButton b;
public test(){
b = new JButton("test");
b.addActionListener(this);
/*without actionlistener is fine*/
//bar.showBar();
add(b);
}
public static void main (String args[]){
test demo = new test();
demo.setVisible(true);
demo.pack();
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("test")){
/*The progress bar does not show up, it show only till it finish*/
bar.showBar();
}
}
}
progressBar class :
import java.awt.*;
import javax.swing.*;
public class progressBar extends JFrame{
static int counter;
DownloadFile df = new DownloadFile();
JLabel downloadMsg, downloading;
static JProgressBar bar;
public progressBar(){
setUndecorated(true);
bar = new JProgressBar();
JPanel msgPanel = new JPanel();
JPanel barPanel = new JPanel();
barPanel.add(bar);
msgPanel.setLayout(new BoxLayout(msgPanel,BoxLayout.X_AXIS));
JPanel main = new JPanel(new BorderLayout());
msgPanel.setBackground(Color.BLACK);
barPanel.setBackground(Color.BLACK);
downloadMsg = new JLabel("Sydney.csv");
downloadMsg.setForeground(Color.WHITE);
downloading = new JLabel("Downloading : ");
downloading.setForeground(Color.WHITE);
msgPanel.setBorder(BorderFactory.createMatteBorder(16, 0, 0, 0, Color.black));
msgPanel.add(Box.createHorizontalStrut(10));
msgPanel.add(downloading);
msgPanel.add(downloadMsg);
main.add(msgPanel,BorderLayout.CENTER);
main.add(barPanel,BorderLayout.SOUTH);
main.setPreferredSize(new Dimension(300,50));
JSetting();
add(main);