下面列出了怎么用javafx.scene.control.SelectionModel的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Focus the given node, handling scrolling if needed.
*/
@Override
public void setFocusNode(final Node node, DataHolder options) {
SelectionModel<TreeItem<Node>> selectionModel = getSelectionModel();
if (getRoot() == null || getRoot().getValue() == null) {
return;
}
mapToMyTree(getRoot().getValue(), node, options.getData(CARET_POSITION))
.map(((ASTTreeItem) getRoot())::findItem)
.ifPresent(found -> {
// don't fire any selection event while itself setting the selected item
suppressibleSelectionEvents.suspendWhile(() -> selectionModel.select(found));
});
getFocusModel().focus(selectionModel.getSelectedIndex());
if (!isIndexVisible(selectionModel.getSelectedIndex())) {
scrollTo(selectionModel.getSelectedIndex());
}
}
@SuppressWarnings("rawtypes")
public static void disableIfNotSelected(SelectionModel selectionModel, Node... nodes) {
BooleanBinding selected = selectionModel.selectedItemProperty().isNull();
for (Node node : nodes) {
node.disableProperty().bind(selected);
}
}
@SuppressWarnings("rawtypes")
public static void disableIfNotSelected(SelectionModel selectionModel, Node... nodes) {
BooleanBinding selected = selectionModel.selectedItemProperty().isNull();
for (Node node : nodes) {
node.disableProperty().bind(selected);
}
}