You should load the file on another Thread
and not the Event Dispatch Thread
. Assuming your loadFromFile
method blocks until it loads the file, you can then hide the layer, but you must hide on the Event Dispatch Thread
and not the new Thread
you started for loading the file.
Remove your timer and replace your try block with this:
try {
new Thread(new Runnable(){
public void run() {
dataManager.loadFromFile("C:/Users/*****PC/Downloads/****.csv");
EventQueue.invokeLater(new Runnable(){
public void run() {
layerUI.stop();
}
});
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}