自定義導航控件不支持。在等待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