I have a swing GUI with border layout. in the NORTH
I have added some component.
My label component which has GIF icon is invisible lblBusy.setVisible(false);
later a button make it visible like below. Why it does not show up?
btnDownload.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
lblBusy.setVisible(true);
btnCancel.setEnabled(true);
}
});
download = new Download(txtSource.getText(), new File(txtDestination.getText()), textAreaStatus);
download.start();
lblBusy.setVisible(false);
}
});
1) this is
EventDispatchThread
rellated issue, EDT quite guaranteed that all changes to the GUI would be done on one moment2) you invoked
ActionPerformed
fromJButton
, and untill all events ended your GUI should be freeze or is unresponsible, same forJButton
andJLabel
in your case3) better would be redirect reading for
File
contents to the Backgroung task e.g.SwingWorker
orRunnable#Thread
thenJButton
andJLabel
will be changed and GUI would be during Background task responsible for Mouse or KeyBoardor
4) dirty hack split to the two separated
Action
delayed byjavax.swing.Timer
, but in this case again untill all events ended your GUI will be freeze or is unresponsible