Tried to implement a global wait cursor, via scene.setCursor.
The problem is that this command doesn't set the cursor immediate. Not all applications can do every method call async.
Test application:
public class WaitCursorTest extends Application
{
private Scene scene;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Button butWait = new Button("Show WAIT cursor");
butWait.setOnAction(e ->
{
scene.setCursor(Cursor.WAIT);
try
{
Thread.sleep(5000);
}
catch (Exception ex)
{
//ignore
}
finally
{
scene.setCursor(Cursor.DEFAULT);
}
});
BorderPane panButton = new BorderPane();
panButton.setCenter(butWait);
scene = new Scene(panButton, 800, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX FlowPane Test");
primaryStage.show();
}
}
Same or similar was possible with Swing without problems:
public class WaitCursorSwingTest extends JFrame
{
public static void main(String[] args)
{
new WaitCursorSwingTest();
}
public WaitCursorSwingTest()
{
BorderLayout blMain = new BorderLayout();
JButton butWait = new JButton("Show WAIT cursor");
butWait.addActionListener(l ->
{
getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
getGlassPane().setVisible(true);
try
{
Thread.sleep(5000);
}
catch (Exception ex)
{
//ignore
}
finally
{
getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
getGlassPane().setVisible(false);
}
});
FlowLayout flCenter = new FlowLayout();
JPanel panCenter = new JPanel(flCenter);
panCenter.add(butWait);
setLayout(blMain);
add(panCenter);
setSize(800, 600);
setLocationRelativeTo(null);
setVisible(true);
}
}
The problem is that this command doesn't set the cursor immediate. Not all applications can do every method call async.
Test application:
public class WaitCursorTest extends Application
{
private Scene scene;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Button butWait = new Button("Show WAIT cursor");
butWait.setOnAction(e ->
{
scene.setCursor(Cursor.WAIT);
try
{
Thread.sleep(5000);
}
catch (Exception ex)
{
//ignore
}
finally
{
scene.setCursor(Cursor.DEFAULT);
}
});
BorderPane panButton = new BorderPane();
panButton.setCenter(butWait);
scene = new Scene(panButton, 800, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX FlowPane Test");
primaryStage.show();
}
}
Same or similar was possible with Swing without problems:
public class WaitCursorSwingTest extends JFrame
{
public static void main(String[] args)
{
new WaitCursorSwingTest();
}
public WaitCursorSwingTest()
{
BorderLayout blMain = new BorderLayout();
JButton butWait = new JButton("Show WAIT cursor");
butWait.addActionListener(l ->
{
getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
getGlassPane().setVisible(true);
try
{
Thread.sleep(5000);
}
catch (Exception ex)
{
//ignore
}
finally
{
getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
getGlassPane().setVisible(false);
}
});
FlowLayout flCenter = new FlowLayout();
JPanel panCenter = new JPanel(flCenter);
panCenter.add(butWait);
setLayout(blMain);
add(panCenter);
setSize(800, 600);
setLocationRelativeTo(null);
setVisible(true);
}
}