在TextInputDialog应用程序中显示我的JavaFX有问题。代码:
TextInputDialog tid = new TextInputDialog("Your name");
tid.setTitle("Table");
tid.setHeaderText("You have won!");
tid.setContentText("Enter your name: ");
tid.showAndWait();我犯了这样一个错误:
Exception in thread "Timer-2" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-2是的,我使用计时器,在我的应用程序中使用三到四个定时器。
GitHub - https://github.com/verygoodat/FlappyBox /src/Application/GameController/ - function setState(int),开关(2),我应该在游戏和游戏中创建一个消息,但是我做不到。那么,是什么原因导致了这个问题呢?
这个Platform.runLater(() -> tid.showAndWait())不起作用
case 2://pause
TextInputDialog tid = new TextInputDialog("Ваше имя");
tid.setTitle("Таблица рекордов");
tid.setHeaderText("Вы побили чей-то рекорд!");
tid.setContentText("Введите ваше имя: ");
Platform.runLater(() -> tid.showAndWait());
Timers.stopTimers();
pr.setFill(Color.rgb(0,0,0,0.5));
pr.clearRect(0,0,pre.getWidth(), pre.getHeight()-50);
pr.fillRect(0,0,pre.getWidth(), pre.getHeight());
pr.setFill(Color.WHITE);
stat = "КОНЕЦ ИГРЫ!";
pr.fillText(stat, WIDTH/2-150, HEIGHT/2);
pr.fillText( "\nPOINTS: "+gamecontroller.score, WIDTH/2-170, HEIGHT/2);
gameover = true;
break;它的工作方式如下:
Platform.runLater(() ->
{
TextInputDialog tid = new TextInputDialog();
tid.setTitle("Таблица рекордов");
tid.setHeaderText("Вы побили чей-то рекорд!");
tid.setContentText("Введите ваше имя: ");
tid.showAndWait();
});发布于 2018-01-04 15:28:52
在JavaFX中,任何更新UI的内容都需要在FX应用程序线程上运行。您可以在自己的线程中使用计时器等做任何您想做的事情,但是您应该在应用程序线程上显示TextInputDialog。
你可以这样做:
Platform.runLater(()->tid.showAndWait());https://stackoverflow.com/questions/48098256
复制相似问题