自定义导航控件不支持。在等待the enhancement request修复时,我们可以应用黑客(如果QA准则允许)如下所述。这是一种黑客行为,因为与导航控件相关的所有内容在PaginationSkin中都是私有的,而PaginationSkin本身还不是public api。
基本的想法是插入额外的节点到核心导航控制,这显然意味着依靠实现细节(不要,不要:-) :-)。我们在实例化时以及每当再次插入下一个按钮时都这样做 - 核心在分页的布局和状态更改期间经常清除其所有子项。这包括:
- 查找包含该按钮的面板,它的选择是控制箱
- 保持其最后一个孩子,这是下一个按钮
- 一个监听器窗格的孩子加入到参考能够插入自定义控件
代码示例自定义皮肤,这里根本就是两个按钮首/末:
public static class CustomPaginationSkin extends PaginationSkin {
private HBox controlBox;
private Button prev;
private Button next;
private Button first;
private Button last;
private void patchNavigation() {
Pagination pagination = getSkinnable();
Node control = pagination.lookup(".control-box");
if (!(control instanceof HBox))
return;
controlBox = (HBox) control;
prev = (Button) controlBox.getChildren().get(0);
next = (Button) controlBox.getChildren().get(controlBox.getChildren().size() - 1);
first = new Button("A");
first.setOnAction(e -> {
pagination.setCurrentPageIndex(0);
});
first.disableProperty().bind(
pagination.currentPageIndexProperty().isEqualTo(0));
last = new Button("Z");
last.setOnAction(e -> {
pagination.setCurrentPageIndex(pagination.getPageCount());
});
last.disableProperty().bind(
pagination.currentPageIndexProperty().isEqualTo(
pagination.getPageCount() - 1));
ListChangeListener childrenListener = c -> {
while (c.next()) {
// implementation detail: when nextButton is added, the setup is complete
if (c.wasAdded() && !c.wasRemoved() // real addition
&& c.getAddedSize() == 1 // single addition
&& c.getAddedSubList().get(0) == next) {
addCustomNodes();
}
}
};
controlBox.getChildren().addListener(childrenListener);
addCustomNodes();
}
protected void addCustomNodes() {
// guarding against duplicate child exception
// (some weird internals that I don't fully understand...)
if (first.getParent() == controlBox) return;
controlBox.getChildren().add(0, first);
controlBox.getChildren().add(last);
}
/**
* @param pagination
*/
public CustomPaginationSkin(Pagination pagination) {
super(pagination);
patchNavigation();
}
}
自定义导航不受支持 - 它是一个包装专用类(NavigationControl),它是硬编码的并且硬连线到PaginationSkin中。你唯一的选择(我可以看到)是用自定义导航控件滚动你自己的皮肤(大多数是c&p)(虽然从未尝试过) – kleopatra
我没有检查过,但如果这不能用公共API更改,你可能想要提交增强请求:http://bugs.java.com/ – Puce
我提出了增强请求:http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8132131 – Stefan