Java swing Loader image not displaying properly? [duplicate] - java

This question already has answers here:
Java swing GUI freezes
(5 answers)
Closed 5 years ago.
I have tried the below code .
Functionality-
Click on Button
It will call a method which will take some time to process.
Need to display Loader image so that user can see that processing is going on.
I tried below but if the loaderLabel1.setVisible(true); before method call doesnot show image and if we comment loaderLabel1.setVisible(false); then it shows loader image after method is finished.
Will actionPerformed method not apply the visibility to Label unless it completes? If yes is there any alternative for this problem?
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TestLoader extends JPanel{
static ImageIcon loading1 = new ImageIcon("D:\\WORKSPACE\\STUDY\\images\\ajax-loader.gif");
static JLabel loaderLabel1 = new JLabel(loading1, JLabel.CENTER);
public TestLoader(){
super(new GridLayout(0, 1));
System.out.println("---------TEST ------");
JPanel submitPanel = new JPanel();
submitPanel.add(clearMessageButton);
this.add(submitPanel);
JPanel LOADER_PANEL = new JPanel();
loaderLabel1.setVisible(false);
LOADER_PANEL.add(loaderLabel1);
this.add(LOADER_PANEL);
}
JButton clearMessageButton = new JButton(new AbstractAction("Test Result") {
#Override
public void actionPerformed(ActionEvent arg0) {
loaderLabel1.setVisible(true);
TestMethod();
loaderLabel1.setVisible(false);
}});
public void TestMethod(){
System.out.println(" =========START TestMethod =========");
try {
Thread.currentThread().sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(" =========complete TestMethod =========");
}
/**
* #param args
*/
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
TestLoader pf = new TestLoader();
pf.display();
}
});
}
private void display() {
JFrame frame = new JFrame("TEST LOADER");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(this);
frame.pack();
frame.setResizable(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}

There is the class SwingWorker that allows you to perform Tasks in a different thread; here's an example of how your code could be changed to use a SwingWorker:
JButton clearMessageButton = new JButton(new AbstractAction("Test Result") {
#Override
public void actionPerformed(ActionEvent arg0) {
SwingWorker worker = new SwingWorker() {
#Override
protected Object doInBackground() throws Exception {
loaderLabel1.setVisible(true);
TestMethod();
return true;
}
public void TestMethod() {
System.out.println(" =========START TestMethod =========");
try {
Thread.currentThread().sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(" =========complete TestMethod =========");
}
protected void done() {
loaderLabel1.setVisible(false);
};
};
worker.execute();
}
});
Note the methods doInBackground() that does the work in the other thread and done() that is called after doInBackground() is finished.

Related

Changing a label text at the start and the end of an ActionListener

I have a process to be performed in an ActionListener call. This process can take some time. So I have to inform that is processing during the time of the execution in a label.
My problem is that Swing doesn't repaint the label during the thread of ActionListener, so I can't show the "Processing" message.
What is the best way to solve that?
package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MyTestPane extends JPanel{
/**
*
*/
private static final long serialVersionUID = 340444475514103360L;
private JLabel myLabel;
private JButton myButton;
public MyTestPane() {
initComponents();
}
private void initComponents() {
myLabel = new JLabel("Ready");
myButton = new JButton("Start");
myButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent arg0) {
myActionListenter();
}
});
add(myLabel);
add(myButton);
}
private void myActionListenter(){
myLabel.setText("Starting count ...");
try{
Thread.sleep(10000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
myLabel.setText("Finishing count ...");
}
public static final void main(String argv[]) {
JFrame frame = new JFrame();
frame.add(new MyTestPane());
frame.pack();
frame.setVisible(true);
}
}
When you want to do something heavy (in terms of time required to be finished), like Thread.sleep, you can't simply do it in the same thread the GUI runs. When your heavy task starts on the same thread as the GUI, the GUI thread is busy calculating your heavy task and therefore it cannot receive any events. That's why the whole GUI freezes. Because it is busy.
Now in order to solve that read concurrency in Swing.
To sum it up for you, all Swing applications must run on their single-per-application thread. This thread is called the Event Dispatch Thread. Because all GUI events (mouse pointers moving, buttons clicked, windows resizing, etc) happen there.
So, when you want to do something heavy, you do it in another thread and since they are invisible to the user(GUI) they are called background threads. Swing has its own API to create background threads. They are called SwingWorkers. You can find how to use one in the doc.
Here is an example of doing something heavy (Thread.sleep) and at the same time publishing the progress (I don't know if you are interested in that). Also, I try to keep things some sort of abstract, in order to keep the concerns separated.
I suggest you to run it and have some experiments with it.
public class WorkerExample {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
MyPanel myPanel = new MyPanel();
myPanel.setPreferredSize(new Dimension(400, 300));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(myPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
});
}
private static class MyPanel extends JPanel implements ProgressableView {
private JLabel countLabel;
private JProgressBar progressBar;
public MyPanel() {
super(new FlowLayout());
countLabel = new JLabel("Progress: 0");
add(countLabel);
progressBar = new JProgressBar();
progressBar.setVisible(false);
add(progressBar);
JButton startHeavyTaskButton = new JButton("Start Heavy Task");
startHeavyTaskButton.addActionListener(e -> {
startHeavyTaskButton.setEnabled(false);
startHeavyTaskButton.setText("Please wait..");
progressBar.setValue(0);
progressBar.setVisible(true);
Runnable restoreButtonAvailability = () -> {
startHeavyTaskButton.setEnabled(true);
startHeavyTaskButton.setText("Start Heavy Task");
};
new DoSomethingHeavyAndShowProgressWorker(this, restoreButtonAvailability).execute();
});
add(startHeavyTaskButton);
}
#Override
public void setProgress(int progress) {
if (progress >= 99) {
countLabel.setText("Finished!!");
progressBar.setVisible(false);
} else {
progressBar.setValue(progress);
countLabel.setText("Progress: " + progress);
}
}
}
private static interface ProgressableView {
void setProgress(int progress);
}
private static class DoSomethingHeavyAndShowProgressWorker extends SwingWorker<Void, Integer> {
private ProgressableView view;
private Runnable onDone;
public DoSomethingHeavyAndShowProgressWorker(ProgressableView view, Runnable onDone) {
this.view = view;
this.onDone = onDone;
}
#Override
protected Void doInBackground() throws Exception {
for (int i = 0; i < 100; i++) {
Thread.sleep(200);
publish((i + 1)); // Publish will call process() method in the GUI thread
}
return null;
}
#Override
protected void process(List<Integer> chunks) {
if (chunks.isEmpty())
return;
int progress = chunks.get(chunks.size() - 1);
view.setProgress(progress);
}
#Override
protected void done() {
try {
get(); // To catch exceptions happend in background
if (onDone != null)
onDone.run();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}
Here is a preview:
I put the counter code in a separate thread so it would run separately from the Event Dispatch Thread that all Swing components must be created and executed.
Here's the complete runnable code.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TimerTestPanel extends JPanel {
private static final long serialVersionUID = 340444475514103360L;
private JLabel myLabel;
private JButton myButton;
public TimerTestPanel() {
initComponents();
}
private void initComponents() {
myLabel = new JLabel("Ready");
myButton = new JButton("Start");
myButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent event) {
myActionListenter();
}
});
add(myLabel);
add(myButton);
}
private void myActionListenter() {
myLabel.setText("Starting count ...");
new Thread(new Counter()).start();
}
public static final void main(String argv[]) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JFrame frame = new JFrame();
frame.add(new TimerTestPanel());
frame.pack();
frame.setVisible(true);
}
});
}
public class Counter implements Runnable {
#Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
myLabel.setText("Finishing count ...");
}
});
}
}
}
I think I can use an invokeLater to perform the process, so the ActionListener can change the label without waiting de long process to be finished, but I don't if it is the best solution.
package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class MyTestPane extends JPanel{
/**
*
*/
private static final long serialVersionUID = 340444475514103360L;
private JLabel myLabel;
private JButton myButton;
public MyTestPane() {
initComponents();
}
private void initComponents() {
myLabel = new JLabel("Ready");
myButton = new JButton("Start");
myButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent arg0) {
myActionListenter();
}
});
add(myLabel);
add(myButton);
}
private void myActionListenter(){
myLabel.setText("Starting count ...");
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
try{
Thread.sleep(10000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
myLabel.setText("Finishing count ...");
}
});
}
public static final void main(String argv[]) {
JFrame frame = new JFrame();
frame.add(new MyTestPane());
frame.pack();
frame.setVisible(true);
}
}

stop infinite loop using stop button

After starting infinite loop, I am unable to close JFrame.
I want to stop infinite loop using stop button.
I am starting an infinite loop using start button. I want close that loop using stop button.
if(stop.getModel().isPressed()){break;} is not working
actionListener used to identify button click and using break statement to terminate while loop is also not working
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class NewClass1 {
private String arg = "";
public NewClass1()
{
JFrame frame = new JFrame("Datacolor software automate");
JButton stop = new JButton("STOP");
stop.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent ae)
{
arg = (String)ae.getActionCommand();
System.out.println(arg);
}
});
JButton button = new JButton("Start");
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent ae) {
int i = 0;
while (true)
{
try {
System.out.println(i);
i++;
if(arg.equals("STOP"))
{
break;
}
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}
});
frame.add(button);
frame.add(stop);
frame.setLayout(new FlowLayout());
frame.setSize(300,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run()
{
new NewClass1();
}
});
}
}
On clicking stop button infinite loop must terminate. I able not able to use any buttons in JFrame after starting infinite loop using start buttton.
You cannot click "Stop" button in the first place, and this is because you run a big task (the while(true) part of your code) in the Event Dispatch Thread which will cause your whole GUI to freeze.
In order to avoid this, and make it work, you will have to use a SwingWorker. A class that allows you to run long/heavy tasks in the background and (optionally) publish them in GUI.
Then, if you want to cancel this SwingWorker, a call to its cancel() method will be enough.
Take a look at the following example:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
public class NewClass1 {
private String arg = "";
private SwingWorker<Void, Integer> worker;
public NewClass1() {
JFrame frame = new JFrame("Datacolor software automate");
JButton stop = new JButton("STOP");
stop.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent ae) {
worker.cancel(true);
}
});
JButton button = new JButton("Start");
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent ae) {
initializeWorker();
worker.execute();
}
});
frame.add(button);
frame.add(stop);
frame.setLayout(new FlowLayout());
frame.setSize(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initializeWorker() {
worker = new SwingWorker<Void, Integer>() {
#Override
protected Void doInBackground() throws Exception {
int i = 0;
while (!isCancelled()) {
i++;
publish(i); // give this i to "process" method
}
return null;
}
#Override
protected void process(List<Integer> chunks) {
int i = chunks.get(0);
System.out.println(i);
}
};
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new NewClass1());
}
}

open same frame when button click in java

i updated the code because many people doesn't understand so write a simple representation for that.
here is the problem whenever i clicked the button it open a new frame but i dont want this it does't open a new frame it remain open the same frame.
code for main frame :
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class JavaProject2_27 {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JavaProject2_27 window = new JavaProject2_27();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public JavaProject2_27() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnClicked = new JButton("Clicked");
btnClicked.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JavaProject2_28 obj=new JavaProject2_28();
obj.getJavaProject2_28();
}
});
btnClicked.setBounds(150, 99, 89, 23);
frame.getContentPane().add(btnClicked);
}
}
code for the second frame :
import java.awt.EventQueue;
import javax.swing.JFrame;
public class JavaProject2_28 {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JavaProject2_28 window = new JavaProject2_28();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public JavaProject2_28() {
initialize();
}
public void getJavaProject2_28()
{
frame.setVisible(true);
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
snapshot
I was checking your earlier program, still cannot find the implementation of getDataJavaProject2_23(); method in those three classes that you provided.
First of all answer to your question few things to mention:
Use proper naming convention, as a example: JavaProject2_28 this class name didnot make any sense to us or even for you if you look at this after a week or two.
You can divide your program for more classes, as a example: database data handling, GUI and etc.
And another important thing is multiple JFrames for one application is not good because of even if you look at your task bar when running your program you can see there is multiple icons, it is difficult to deal with your application. There is more disadvatages about this. read this to get clear idea. Instead of multiple JFrames you can use one JFrame and multiple JPanel with appropriate layouts.
Answer for your updated question:
whenever i clicked the button it open a new frame but i dont want this
it does't open a new frame it remain open the same frame.
I checked your program it is work fine(after press the button open up the other frame).
You can do some changes that are unnecessary:
Remove this function
public void getJavaProject2_28()
{
frame.setVisible(true);
}
And add frame.setVisible(true); to the initialize() method.
Solution:
Add frame.setVisible(true) to button action.
Like below:
}
});
btnClicked.setBounds(150, 99, 89, 23);
frame.getContentPane().add(btnClicked);
frame.setVisible(true);
}
And in the main frame(which is button button added) change like below:
JButton btnClicked = new JButton("Clicked");
btnClicked.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JavaProject2_28 obj=new JavaProject2_28();
}
});
Also you do not need the main() method in both if you are only open second JFrame in main frame button.
I solved It Please A look :
Parent Class:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class ParentClass {
private JFrame frame;
private int Count;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ParentClass window = new ParentClass();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public ParentClass() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnClicked = new JButton("Clicked");
btnClicked.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
Count++;
System.out.println("Count = "+Count);
if(Count==1)
{
ChildClass obj=new ChildClass();
obj.ChildClassVisibility();
}
}
});
btnClicked.setBounds(150, 99, 89, 23);
frame.getContentPane().add(btnClicked);
}
}
ChildClass:
import java.awt.EventQueue;
import javax.swing.JFrame;
public class ChildClass {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ChildClass window = new ChildClass();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public ChildClass() {
initialize();
}
public void ChildClassVisibility()
{
frame.setVisible(true);
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

how to notify all the threads if there is unknown number of threads in java

This is a part of my java code. In this code there are labels which are counting numbers from 0 up to so on.
I want to stop labels to count when I click the button 1st time, and I want to restart the labels to count again when I click the button 2nd time. The problem is that the labels are not restarting their counting when I am clicking the button 2nd time. So please tell me how should I notify all the labels to restart their counting?
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingWorker;
public class Main implements ActionListener {
JButton button = new JButton("Click");
JFrame frame = new JFrame();
boolean wait=false;
public static void main(String arg[]) {
new Main();
}
public Main() {
frame.setLayout(new FlowLayout());
frame.getContentPane().setBackground(Color.BLACK);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
button.addActionListener(this);
frame.add(button);
frame.setVisible(true);
new Producer().execute();
}
public class Producer extends SwingWorker<Void, Void> {
public Void doInBackground() {
for(int infinite=0; infinite!=-1; infinite++) {
new Counter().execute();
try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
}
return null;
}
}
public class Counter extends SwingWorker<Void, Void> {
JLabel label = new JLabel();
public Counter() {
label.setForeground(Color.WHITE);
frame.add(label);
}
public Void doInBackground() {
synchronized (this) {
for(int i=0; i!=-1; i++) {
if(wait==true)
try {this.wait();} catch(Exception exp) {exp.printStackTrace();}
label.setText(""+i);
try {Thread.sleep(200);} catch (InterruptedException e) {e.printStackTrace();}
}
}
return null;
}
}
public void actionPerformed(ActionEvent clicked) {
if(wait==false)
wait=true;
else if(wait==true) {
synchronized (this) {
this.notifyAll();
}
wait=false;
}
}
}
The this in this.notifyAll() is not the same object as the this in this.wait().

Using SwingWorker to update the progress of a thread from another class

Value is updated by the end, but not during the process. I guess the reason is that the publish method locates outside the loop.
As to invoke PropertyChangeListener, can it be achieved by defining the class without extends SwingWorker<Void, Void> ?
To address the question in another way, I have two threads locate in two different classes. Is it possible to build communication between the two using SwingWorker?
Class Application
import javax.swing.JFrame;
public class Application {
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
#Override
public void run() {
JFrame frame = new Progress();
frame.setSize(200, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}
Class Progress
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;
#SuppressWarnings("serial")
public class Progress extends JFrame{
private JProgressBar progressbar;
public Progress(){
JButton button = new JButton("Run");
progressbar = new JProgressBar(0, 100);
progressbar.setValue(0);
progressbar.setStringPainted(true);
JPanel panel = new JPanel();
panel.add(button);
panel.add(progressbar);
add(panel, BorderLayout.PAGE_START);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
start();
}
});
}
private void start(){
progressbar.setValue(0);
SwingWorker<Void, Integer> worker = new SwingWorker<Void, Integer>(){
#Override
protected Void doInBackground() throws Exception {
Simulation sim = new Simulation();
publish(sim.getCount());
return null;
}
#Override
protected void process(List<Integer> chunks) {
Integer progress = chunks.get(chunks.size()-1);
progressbar.setValue(progress);
progressbar.repaint();
progressbar.update(progressbar.getGraphics());
}
#Override
protected void done() {
Toolkit.getDefaultToolkit().beep();
}
};
worker.execute();
}
}
Class Simulation
public class Simulation {
private int count;
public Simulation(){
for(int i=0; i<100; i++){
count++;
System.out.println(count);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public int getCount(){
return count;
}
}
How can I update the value during the process?
You need to implement PropertyChangeListener on your SwingWorker and listen to the Progress property changes and then from overridden propertChange() method update your JProgressBar.
Here is what you are looking.
Hope this helps.

Categories

Resources