Hello,
I am trying to add a loading Icon on my application.
It is basically a GIF of a rotating circle.
Whenever the user presses the Search button, and sends a request to the DataBase for some information, the loading icon should be shown and then it should disappear whenever the loading process is completed.
Here is a piece of code:
Icon = new ImageIcon("load.gif"); JLabel L = new JLabel(Icon); L.setBounds(0, 50, 65, 65); L.setVisible(false);
This is called on the init() method of the class.
Whenever the user presses the search button the method 'loading()' is invoked, it basically does:
L.setVisible(true);
and of coure the other method, 'stopload()' does:
L.setVisible(false);
The problem is that the loading icon is not shown.
I figured out that problem might be related to the fact that the GUI does not refresh (or show the component) in time and the icon is set back to visible(false) before it can be shown.
In fact, if I do not put the 'stopload()' the icon is shown properly but, of course, does not stop.
I have tried to add:
Frame.pack(); Frame.revalidate(); Frame.repaint()
or also
[the icon is added on this Panel]Panel.validate(); Panel.repaint();
and this nothing...
Basically the GUI is properly refreshed only when the Table (containing the results of the query) is shown/updated.
I have also tried to invoke the start method using a Thread, eg:
ThreadIcreated.start();
but still nothing changes..
PS. I always had problems in refreshing the Panel or Frame. In fact, for another issue I had to use some sort of trick in order to force the repaint of a specific component.
I used:
Panel.setvisible(false); Panel.setvisible(true);
[I basically hide and show the panel]
I tried to run that same method that works for another component, but it does not work for this...
I wish you a good day!
N.