JProgressBar .... need assistance please..

R

Russell

I'm playing with the idea of showing a JProgressBar in a small App' I trying
to make.
I want to display the progress of an array being populated....however I cant
seem to get the bar to show the actual % state before it reaches 100%
Am I missing something out?
Please help me if you can..

Thanks...

#######################
CODE BELOW
#######################

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ArrayRandom extends JFrame {
protected final int size = 100000;
protected int[] prodRandm = new int[size];
protected int min = 0;
protected int max = 100;
protected JProgressBar progress;
protected JButton start;

public ArrayRandom() {
setSize(300,50);
progress = new JProgressBar();
progress.setStringPainted(false);
progress.setIndeterminate(true);

start = new JButton("Start");
ActionListener act = new ActionListener() {
public void actionPerformed(ActionEvent e) {
progress.setMinimum(min);
progress.setMaximum(max);
progress.setIndeterminate(false);
progress.setStringPainted(true);
for (int i = 0; i < size; i++) {
prodRandm = i;
progress.setValue((i/1000)+1);
progress.setString((i/1000)+1+" %");
}
}
};
start.addActionListener(act);
getContentPane().setLayout(new BorderLayout(10,10));
getContentPane().add(progress, BorderLayout.CENTER);
getContentPane().add(start, BorderLayout.WEST);
}

public static void main(String[] args) {
ArrayRandom frame = new ArrayRandom();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
 
A

Alex Hunsley

Russell said:
I'm playing with the idea of showing a JProgressBar in a small App' I trying
to make.
I want to display the progress of an array being populated....however I cant
seem to get the bar to show the actual % state before it reaches 100%
Am I missing something out?
Please help me if you can..

Thanks...

Russell, please don't multipost (there is never any good reason to).

http://www.blakjak.demon.co.uk/mul_crss.htm

You question is much more suited to comp.lang.java.help, where I have
answered it. In future it would be good to restrict similar questions to
that newsgroup.

alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top