【问题标题】:How to enable a dropdown list of predetermined items to add to a custom control in SceneBuilder?如何启用预定项目的下拉列表以添加到 SceneBuilder 中的自定义控件?
【发布时间】:2018-03-15 07:14:04
【问题描述】:

DialogPaneSceneBuilder 中有这个实现:

您可以在窗格中添加按钮列表。

我希望为我在场景构建器中的自定义控件执行此操作。我在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


【解决方案1】:

您应该尝试点击右上角设置图标上的库面板,然后点击 Costum Library 文件夹 -> 在资源管理器中显示。

有关详细信息,请参阅this tutorial

【讨论】:

  • 这个控件不是自定义的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多