I want to show the MaskerPane from ControlsFx if a network request is executed. It should be an indicator if the request is still running. Also i want to run the network request in the background so the window doesn't freeze.
private void search(String searchTerm, boolean tvShow){
masker.setVisible(true);
ExecutorService executor = Executors.newSingleThreadExecutor();
Callable<List<String>> callable = new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
return tmdbWrapper.search(searchTerm, tvShow);
}
};
Future<List<String>> future = executor.submit(callable);
executor.shutdown();
try {
System.out.println(future.get().toString());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} finally {
System.out.println("finally");
masker.setVisible(false);
}
The problem is, that the MaskerPane doesn't show until the request is finished.
tmdbWrapper is a Wrapper for the tmdb Api.
If I would do something like this
new Thread(){
@Override
public synchronized void run(){
masker.setVisible(true);
System.out.println(tmdbWrapper.search(searchTerm, tvShow));
masker.setVisible(false);
}
}.start();
it would work. Because it would be bad coding style and won't be an FX-application Thread I don't want it to do it like that.