I have an onClick event in Java Swing.
private void fastForward(java.awt.event.MouseEvent evt) { 
    loading.setVisible(true);
    //some time consuming algorithm
    loading.setVisible(false);      
}
In it, I perform a operation that consumes a lot of time, so I want to display a loading animation.
I created one as a button with a icon which a loading gif, I set the visibility of the button to false. In the onClick event I set the visibility to true. The problem is that button becomes visible when the whole function executes, which is not what I want. I want the button to be displayed during the execution of the function. How can I set the button to visible during execution.