2015-07-21 84 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(); 
        } 
    
    } 
    
    相关问题