【发布时间】:2018-03-15 07:14:04
【问题描述】:
DialogPane 在SceneBuilder 中有这个实现:
您可以在窗格中添加按钮列表。
我希望为我在场景构建器中的自定义控件执行此操作。我在DialogPane 的构造函数中找不到任何明显的东西可以使它工作。
这样做有可能吗?
private final ObservableList<ButtonType> buttons = FXCollections.observableArrayList();
public DialogPane() {
getStyleClass().add("dialog-pane");
headerTextPanel = new GridPane();
getChildren().add(headerTextPanel);
graphicContainer = new StackPane();
contentLabel = createContentLabel("");
getChildren().add(contentLabel);
buttonBar = createButtonBar();
if (buttonBar != null) {
getChildren().add(buttonBar);
}
buttons.addListener((ListChangeListener<ButtonType>) c -> {
while (c.next()) {
if (c.wasRemoved()) {
for (ButtonType cmd : c.getRemoved()) {
buttonNodes.remove(cmd);
}
}
if (c.wasAdded()) {
for (ButtonType cmd : c.getAddedSubList()) {
if (! buttonNodes.containsKey(cmd)) {
buttonNodes.put(cmd, createButton(cmd));
}
}
}
}
});
}
【问题讨论】:
-
有趣... 了解其工作原理的地方可能是Scene Builder 的源代码。您需要弄清楚它是否只是将
DialogPane中的此属性视为特殊情况(在这种情况下您可能不走运),或者它是否寻找特定的东西(具有某些常量的类型的只读属性定义为相同的类型,或其他东西......)。
标签: java javafx fxml scenebuilder