第一次提问,所以请原谅任何丢失/错误放置的信息,当然还有我糟糕的英语。作为一个德国人不得不这么说。 ;)
简单而简短,我尝试使用以下方法将 Nodes
添加到 Dialog
中
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.application.Application; 导入javafx.stage.Stage;
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”之外,它是空的。
编辑:添加了我在编写问题时忘记的 showAndWait();
调用。
最佳答案
经过一番修改,我找到了解决方案。
getDialogPane().getChildren.addAll()
不会添加节点以使它们可见。应使用 Pane 添加节点并使用 getDialogPane().setContent
关于java - 尝试将项目添加到对话框,但它们没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47709537/