I wanted to create a "Please wait" animation while, my algorithm is running, that's what I did
public void mouseClicked(MouseEvent arg0) {
res.add(image);
res.setVisible(true);
String input = txtFind.getText();
Engine engine = new Engine(input);
engine.generate();
List<String> s = engine.getList();
res.remove(image);
s.forEach(x -> {
JLabel txt = new JLabel(x);
res.add(txt);
});
}
The idea behind is to display my gif animation when I click on a button, then call my heavy function "generate", once done, I remove my animation and display the results,
However, Im getting another behavior : res becomes visible but without the animation, and then after some seconds (while generate is running) it displays the results.. I noticed that if I remove all my "res.add(txt)" and remove also "res.remove(image)" I still don't get the right behavior as it displays animation only after generate() finishes running and not at the same time.. It feels like the function is not runned sequentially