java试图将项目添加到对话框中,但无法显示
第一次询问,所以请原谅任何遗漏/错误的信息,当然还有我糟糕的英语。作为一个德国人,我不得不这么说
简单而简短,我尝试使用
dialogPane.getChildren.add()
Code:
The Class signature:
public class VerteilDialog extends Dialog<Void>
Declaration of the needed items:
private Label _jlVersionNum;
private TextField _tfVersionNum;
private Label _jlSonstiges;
private TextArea _taSonstiges;
ButtonType btAbbrechen = new ButtonType("Abbrechen", ButtonData.CANCEL_CLOSE);
ButtonType btOk = new ButtonType("Ok", ButtonData.OK_DONE);
getDialogPane().getButtonTypes().add(btAbbrechen);
getDialogPane().getButtonTypes().add(btOk);``
And initialization of those in the contructor:
_jlVersionNum = new Label("Versionsnummer:");
_tfVersionNum = new TextField("4.10.x");
_jlSonstiges = new Label("Sonstiges:");
_taSonstiges = new TextArea();
_jlEinDatum = new Label("Einsatz am:");
And I add the Items like this:
getDialogPane().getChildren().addAll(_tfEinDatum, _jlVersionNum, _tfVersionNum, _jlSonstiges, _taSonstiges);
and Show the dialog
showAndWait();
调用对话框发生在以下位置: 导入javafx。应用应用 导入javafx。阶段舞台
public class MainKlasse extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage arg0) throws Exception {
new VerteilDialog();
}
}
我希望能够正确地添加这些项,而不会出现进一步的问题,但是(这就是我在这里的原因): 对话框显示时没有进一步的错误或任何异常,但除了按钮“Ok”和“Abbrechen”之外,它是空的
Edit:添加了我在写问题时忘记的showAndWait();
调用强>
# 1 楼答案
经过一番修补,我找到了一个解决办法
getDialogPane().getChildren.addAll()
不添加节点以使其可见。应该使用窗格向添加节点,并使用getDialogPane().setContent
将窗格设置为内容