How to change Mouse cursor icon in tornadoFx

230 Views Asked by At

I am working with a project and using tornadoFx. When i need to change my mouser cursor icon to indicate background task running . how to do that ? if i do: cursor = Cursor.WAITING cursor doesn't change.

1

There are 1 best solutions below

0
On BEST ANSWER

You need to configure the cursor on the outermost object you want to change the cursor for. In the following example, I make sure that the cursor changes for the stackpane which is the root of the View. That means that while the action is running, the cursor will change as long as your mouse pointer is somewhere inside of the stackpane:

class TaskView : View() {
    override val root: StackPane = stackpane {
        setMinSize(400.0, 400.0)
        button("Do work") {
            action {
                parent.cursor = Cursor.WAIT
                runAsync {
                    Thread.sleep(2000)
                } ui {
                    parent.cursor = Cursor.DEFAULT
                }
            }
        }
    }
}