相关疑难解决方法(0)

将自定义组件添加到SceneBuilder 2.0

我需要在窗格上有一个选择侦听器和select方法,以便能够在单击节点时监视并显示突出显示.

我做了以下事情:

public class PaneWithSelectionListener extends Pane {

    private ObjectProperty<Annotation> selectedAnnotation = new SimpleObjectProperty<>();

    public PaneWithSelectionListener() { 
        super();
        selectedAnnotation.addListener((obs, oldAnno, newAnno) -> {
            if (oldAnno != null) {
                oldAnno.setStyle("");
            }
            if (newAnno != null) {
                newAnno.setStyle("-fx-border-color: blue;-fx-border-insets: 5;-fx-border-width: 1;-fx-border-style: dashed;");
            }
        });

        setOnMouseClicked(e->selectAnnotation(null));
    }

    public void selectAnnotation(Annotation ann){
        selectedAnnotation.set(ann);
    }
}
Run Code Online (Sandbox Code Playgroud)

这很有效 - 但是我不能再使用SceneBuilder了,因为我的FXML引用了这个PaneWithSelectionListener而不是Pane.我不确定如何将自定义窗格导入SceneBuilder.我已经看了其他问题,它们都是FXML和控制器的组合 - 这只是一个Pane.

有没有人知道这样做的方法,或者可能在初始化时交换Panea PaneWithSelectionListener

谢谢

javafx scenebuilder javafx-8

15
推荐指数
1
解决办法
1万
查看次数

标签 统计

javafx ×1

javafx-8 ×1

scenebuilder ×1