2015-07-21 78 views
2

我想使用分頁顯示明智的表格頁面。這工作原則,但我想補充一點,是在同一行作爲默認的分頁導航額外的控制:如何擴展JavaFX分頁導航以顯示其他控件?

用於將第一頁(「< <」)
  • 文本字段用於跳轉到
    • 按鈕指定頁面索引
    • 按鈕去最後一頁(「>>」)
    • 文本字段每頁條目跳轉到包含給定ID的行條目頁面
    • 搜索文本字段的數量。

    我能夠使用setPageFactory()方法自定義分頁控件上方的頁面,但我無法自定義導航控件本身。怎麼做?如果我想補充的上方或下方的默認導航我額外的控制我浪費了一些空間:

    enter image description here

    相關文章: JavaFX Pagination, adding <<and>>> options

    提起enhancement request

  • +0

    自定義導航不受支持 - 它是一個包裝專用類(NavigationControl),它是硬編碼的並且硬連線到PaginationSkin中。你唯一的選擇(我可以看到)是用自定義導航控件滾動你自己的皮膚(大多數是c&p)(雖然從未嘗試過) – kleopatra

    +0

    我沒有檢查過,但如果這不能用公共API更改,你可能想要提交增強請求:http://bugs.java.com/ – Puce

    +1

    我提出了增強請求:http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8132131 – Stefan

    回答

    3

    自定義導航控件不支持。在等待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(); 
        } 
    
    } 
    
    相關問題