मान लिया जाये कि आप JavaFX आवेदन धागे की बंद निम्नलिखित कोड चल रहे हैं, एक प्रतीक्षा कर्सर प्रदर्शित करने के लिए एक पैटर्न हो सकता है:
Platform.runLater(new Runnable() {
@Override
public void run() {
getStage().getScene().setCursor(Cursor.WAIT);
}
});
// Do some stuff
Platform.runLater(new Runnable() {
@Override
public void run() {
getStage().getScene().setCursor(Cursor.DEFAULT);
}
});
या, यदि आप JavaFX आवेदन धागे पर पहले से ही कर रहे हैं, तो आप इस्तेमाल कर सकते हैं एक Service:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.concurrent.*;
import javafx.event.*;
import javafx.geometry.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ServiceWithCursorControl extends Application {
private final Button runButton = new Button("Run");
private final Label label = new Label();
private final Service service = new Service() {
@Override
protected Task createTask() {
return new Task<Void>() {
@Override protected Void call() throws Exception {
// do stuff
Thread.sleep(5000);
return null;
}
};
}
};
@Override public void start(Stage stage) {
VBox layout = createLayout();
Scene scene = new Scene(layout, 100, 80);
stage.setScene(scene);
bindUIandService(stage);
stage.show();
}
private void bindUIandService(Stage stage) {
label.textProperty()
.bind(
service.stateProperty().asString()
);
stage.getScene()
.getRoot()
.cursorProperty()
.bind(
Bindings
.when(service.runningProperty())
.then(Cursor.WAIT)
.otherwise(Cursor.DEFAULT)
);
runButton
.disableProperty()
.bind(
service.runningProperty()
);
runButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
service.restart();
}
});
}
private VBox createLayout() {
VBox layout = new VBox(10);
layout.getChildren().setAll(runButton, label);
layout.setPadding(new Insets(10));
layout.setAlignment(Pos.CENTER);
return layout;
}
public static void main(String[] args) {
launch(args);
}
}
यह अपने विवरण जो दृष्टिकोण आपकी समस्या को सबसे अच्छा फिट बैठता है से स्पष्ट नहीं है, लेकिन उम्मीद है कि आप इस पर काम कर सकते हैं।
सेट कर्सर को एफएक्स थ्रेड पर बुलाया जाना चाहिए ... – assylias