ฉันมีเรียนวิชาหลัก
public class Main {
public static void main(String[] args) {
Application.launch(View.class);
View view = new View();
Platform.runLater(() -> view.changeTitle());
}
}
และคลาส JavaFX ดู
public class View extends Application {
Stage primaryStage;
public View() {
}
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
this.primaryStage = primaryStage;
primaryStage.show();
}
public void changeTitle() {
primaryStage.setTitle("YEA!");
}
}
ฉันต้องการให้คลาสหลักทำอะไรบางอย่างในเธรด JavaFX แต่โค้ดของฉันใช้งานไม่ได้ ในเอกสารบอกว่าฉันสามารถเรียก Platform.runLater() จากเธรดใดก็ได้ที่ฉันต้องการ ถ้าฉันเรียก Platform.runLater() จากเธรด JavaFX (ใน start() เป็นต้น) ทุกอย่างก็โอเค