我在 Windows 10 上运行的 JavaFX 中有一个小应用程序,我已经更改了应用程序内部的许多内容,现在我面临的问题是我的 InfoBox 显示标题和图片,但框中没有文字。
我在我的应用程序的一部分中调用它:
infoBox("Karte wurde gelesen... bitte warten ", "Information-NFC", "Information-NFC!");
Run Code Online (Sandbox Code Playgroud)
这是函数本身:
public void infoBox(String infoMessage, String titleBar, String headerMessage)
{
Alert alert = new Alert(AlertType.INFORMATION);
alert.setResizable(true);
alert.getDialogPane().setPrefSize(480, 320);
alert.getDialogPane().setStyle("-fx-text-fill: red;-fx-font-size: 15px; -fx-font: 10px Tahoma; ");
alert.setTitle(titleBar);
alert.setHeaderText(headerMessage);
alert.setContentText(infoMessage);
System.out.println(infoMessage+"here");
//Logo für Programm Fenster
//////////// Logo ProgrammFesnter end
Image img2 = new Image(getClass().getResourceAsStream("logo.PNG"));
Stage dialogStage = (Stage) alert.getDialogPane().getScene().getWindow();
dialogStage.getIcons().add(img2);
alert.show();
try {
Thread.sleep(8000);
} catch (InterruptedException ex) {
System.out.println(ex);
}
alert.close();
}
Run Code Online (Sandbox Code Playgroud)
我可以在日志窗口中看到设置了变量“infoMessage”,但警报框本身是空的。我不知道为什么。你们中有人以前遇到过这个问题吗?
除了这个小盒子外,一切都运行良好...... ???
谢谢大家,祝大家假期愉快....
史蒂夫
最有可能的问题是Thread.sleep(8000)通话。这会使JavaFX 应用程序线程休眠,从而阻止用户与 UI 交互,并阻止调度任何渲染“脉冲”。换句话说,您的应用程序在这 8 秒内没有响应。
如果要延迟 FX 线程上的操作,则应使用动画 API。并且由于您似乎希望在允许代码继续之前等待警报关闭,因此您还应该使用 的onShown属性和showAndWait()方法Dialog。例如:
Alert alert = ...;
// configure alert
PauseTransition closeDelay = new PauseTransition(Duration.seconds(8));
closeDelay.setOnFinished(e -> alert.close());
alert.setOnShown(e -> closeDelay.playFromStart());
alert.showAndWait();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |