< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/skin/NestedTableColumnHeader.java

Print this page

        

@@ -120,11 +120,11 @@
 
         getStyleClass().setAll("nested-column-header");
         setFocusTraversable(false);
 
         // init UI
-        label = new TableColumnHeader(skin, getTableColumn());
+        label = createTableColumnHeader(getTableColumn());
         label.setTableHeaderRow(getTableHeaderRow());
         label.setParentHeader(getParentHeader());
         label.setNestedColumnHeader(this);
 
         if (getTableColumn() != null) {

@@ -354,19 +354,28 @@
 
         return height + label.prefHeight(-1) + snappedTopInset() + snappedBottomInset();
     }
 
     /**
-     * Creates a new TableColumnHeader instance for the given TableColumnBase instance. By default this method should
-     * not be overridden, but in some circumstances it makes sense (e.g. testing, or when extreme customization is desired).
-     * If the given TableColumnBase instance has child columns, then it is suggested to return a
-     * {@link NestedTableColumnHeader} instance instead.
+     * Creates a new TableColumnHeader instance for the given TableColumnBase instance. The general pattern for
+     * implementing this method is as follows:
+     *
+     * <ul>
+     *     <li>If the given TableColumnBase instance is null, has no child columns, or if the given TableColumnBase
+     *         instance equals the TableColumnBase instance returned by calling {@link #getTableColumn()}, then it is
+     *         suggested to return a {@link TableColumnHeader} instance comprised of the given column.</li>
+     *     <li>Otherwise, we can presume that the given TableColumnBase instance has child columns, and in this case
+     *         it is suggested to return a {@link NestedTableColumnHeader} instance instead.</li>
+     * </ul>
+     *
+     * <strong>Note: </strong>In most circumstances this method should not be overridden, but in some circumstances it
+     * makes sense (e.g. testing, or when extreme customization is desired).
      *
      * @return A new TableColumnHeader instance.
      */
     protected TableColumnHeader createTableColumnHeader(TableColumnBase col) {
-        return col.getColumns().isEmpty() ?
+        return col == null || col.getColumns().isEmpty() || col == getTableColumn() ?
                 new TableColumnHeader(getTableViewSkin(), col) :
                 new NestedTableColumnHeader(getTableViewSkin(), col);
     }
 
 
< prev index next >