|
|
|
|
|
|
Re: SWT on JavaFX still worked on? [message #1739250 is a reply to message #1739244] |
Thu, 28 July 2016 22:30 |
|
One SWT feature I would quite like is BusyIndicator. My app is client-server, so I have quite a few situations where a user action is going to take a couple of seconds, long enough that I want to provide feedback to the user that something is happening, but not long enough that you really want to go asynchronous with a background task and a callback. Think of check-out/check-in operations in a version control system. The SWT BusyIndicator is very useful for this scenario, just updating the cursor until the Runnable finishes. I came up with the following as a JavaFX equivalent, but it doesn't seem to be all that reliable - quite often the wait cursor doesn't show at all, or only briefly at the end. I'm not sure if this is just a limitation of JavaFX or if there is a better way to do it.
public static void showWhile(Scene scene, Runnable runnable) {
Cursor cache = scene.getCursor();
scene.setCursor(Cursor.WAIT);
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
try {
Platform.runLater(runnable);
} finally {
Platform.runLater(() -> scene.setCursor(cache != null ? cache : Cursor.DEFAULT));
}
return null;
}
};
new Thread(task).start();
}
Colin Sharples
CTG Games Ltd
Wellington, New Zealand
|
|
|
Powered by
FUDForum. Page generated in 0.03784 seconds