In my Java GUI application, I have JButton , and when I click on it, it calls function to connect to the database , then calls function until clear a table in DB , then calls function , which reads text from a single file and loads variables , which calls function , which reads text from another file, compares data with both, and then calls function on update or insert data in the database, all this works fine.
However, my question is related to JButton , when I clicked it, I want to run Indeterminate progress bar only so that the user knows that the work is in progress, and then right before he leaves the action listener setIndeterminate to false , and set the value to progress bar to 100(complete) , but in my case, when you press the button , it remains in a click state, and the progress bar freezes.
What should I implement to prevent this? perhaps? but Im brand new for slicing in java. here is my action listener:
private class buttonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if( e.getSource() == genButton ) { progressBar.setIndeterminate(true); progressBar.setString(null); try { dbConnect();
On the side of the note, I would like the action bar to really move as the program progresses, but I was not sure how to control its progress.
Thank you beef.
UPDATE here is my example of SwingWorker and how I used it:
Globally announced
private functionWorker task; private abstract class functionWorker extends SwingWorker { public void execute() { try { dbConnect(); } catch (SQLException e) { e.printStackTrace(); } clearSchedules(); try { readFile(); } catch (IOException e) { e.printStackTrace(); } dbClose(); } }
Inside my actionPerformed method
if( e.getSource() == genButton ) { progressBar.setIndeterminate(true); progressBar.setString(null); try { task.execute(); progressBar.setIndeterminate(false); progressBar.setValue(100); } catch (Exception e1){ System.err.println("Error: " + e1.getMessage()); } }