私はテキストファイルを読むプログラムを作っています。私がしたいのは、ファイルの読み込みの前または途中に別のスレッドで作成された任意のノード(アラートまたはその他のノード)を表示することです。私はこのようなTask
とPlatform.runLater()
を使用してみました:FXスレッド中にノードを表示することはできますか?
if (filetoopen != null)
{
Platform.runLater(new Runnable() {
@Override
void run() {
Alert alert=new Alert(Alert.AlertType.INFORMATION)
alert.setHeaderText('TEST')
}
})
//method to read the file
Tools.convertFromFile(filetoopen,newredactor)
lastDirectory = filetoopen.getParentFile()
}
私は、ファイルを読み込むのアラートやプログレスバーを表示したいのですが、読み取りが終了した後、コントロールが初期化されます。ですから、ファイルが読み込まれている間に進行状況バーを表示することは可能ですか?または私が作成したRunnableは常に最後に実行されますか?
編集:タスクとの試み:
class Alerter extends Task{
Alerter(File f,Editor e)
{
file=f
editor=e
}
File file
Editor editor
@Override
protected Object call() throws Exception {
Dialog dialog=new Dialog()
DialogPane dp=dialog.getDialogPane()
dp.setHeaderText('TEST')
dp.getButtonTypes().add(new ButtonType('Cancel',ButtonBar.ButtonData.CANCEL_CLOSE))
dialog.setOnCloseRequest(new javafx.event.EventHandler<DialogEvent>() {
@Override
void handle(DialogEvent event) {
dialog.close()
}
})
dialog.show()
Tools.convertFromFile(file,editor)
return null
}
}
ダイアログがまだTools.convertFromFile
後に初期化します。
「私は、 ')' Task'と 'Platform.runLaterを(使用してみました」:それは正しいです方法はありますが、投稿されたコードには「タスク」はありません。 –
OK、タスク – Alexiy
で試行を追加しました。controlsFXとProgressDialogを見てください。タスクを送信してから開始すると、必要なものが表示されます。 –