I am trying to update a JProgressBar in a for loop , The maximum size , I have set is equal to the size of the array which is computed upon and I am incrementing the value of the progress bar in the for loop.Here 's the code
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jProgressBar2.setValue(0);
for (int i = 0; i < area1.length; i++) {
jProgressBar2.setMaximum(length);
if (stopword.contains(area1[i]) || stopword.contains(area1[i].toLowerCase()) || area1[i].equals(" ") || area1[i].length() < 3) {
} else {
jProgressBar2.setBorderPainted(true);
System.out.println(area1[i]);
jTextArea2.append(area1[i] + " ");
jTextArea2.setCaretPosition(jTextArea2.getDocument().getLength());
area3 = jTextArea2.getText();
}
int x = jProgressBar2.getValue();
int z = (int) (jProgressBar2.getPercentComplete() * 100);
System.out.println(z);
jProgressBar2.setAlignmentX(JProgressBar.TOP+100);
jProgressBar2.repaint();
jProgressBar2.setValue(x + 1);
jTextArea2.repaint();
repaint();
}
System.out.println(jProgressBar2.getValue());
}
But the problem is the progress bar goes from 1 to 100 and doesn't show any processing , Moreover for long text (Larger array size) , the view freezes , GUI doesn't get repainted and the processing goes on , and when processing is over , then only the text is appended into the text area and Jprogress bar goes from 1 to 100 , I have also used delay and threads but with the same problem , What would i need to do to show the progress bar go slowly .