I have to query database to get data to write on JLabel and to accelerate opening dialog
I have created JLabel with no text and set text after
To make your Swing Worker to do the background work you need to call the SwingWorker#execute() method. If you don't add it, well... it won't know when to start working. It's like any other variable like:
JLabel label = new JLabel("Hello world");
But if you never add that label to anything (or like an ActionListener not added to the JButton) it will never be added / executed.
worker.execute();
Inside your constructor or wherever you want it to start working.
As per @MadProgrammer's comment:
Remember,
SwingWorkercan return data, so instead of returningBoolean, you could returnStringand usegetin thedonemethod to get the returns of the worker, somewhat safer and more usable then using an instance field
He refers to change your worker's code like this:
SwingWorker worker = new SwingWorker<Boolean, Void>() {
@Override
public String doInBackground() {
return "<html><center>Lecture X : " + ticketDAO.getLectureX() + "</center></html>";
}
@Override
public void done() {
lectureXlabel.setText(get());
lectureXlabel.revalidate();
lectureXlabel.repaint();
componentsPanel.revalidate();
componentsPanel.repaint();
getContentPane().revalidate();
getContentPane().repaint();
}
};