I am on the main thread. When choosing an item from the menu a database has to be called before the gui can show the new panel. This takes some time. During this time I want to show the wait-cursor. I found a way but the code looks ugly. How could this be done more elegant? This question is different from others because the long running task is working on the gui.
menuitem.setOnAction(event -> { szene.setCursor(Cursor.WAIT);
Task<Void> task = new Task<Void>()
{
@Override
public Void call() throws Exception
{
Platform.runLater(new Runnable()
{
@Override
public void run()
{
// do some stuff
szene.setCursor(Cursor.DEFAULT);
}
});
return null;
};
};
new Thread(task).start();
});