Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8166025

TableColumnHeader: loses custom style classes

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u102, 9
    • Fix Version/s: 9
    • Component/s: javafx

      Description

      This happens when the styleclass of its tableColumn is changed. An example of a "custom" style is "nested-column-header" (but note: it's really only an example, happens to all custom styles in all custom header!)

      Below is an example that demonstrates the effect: it has a custom style rule for a nested column under a nested column (white background and padding to see). Run and

      - see the custom style in the second column
      - click on the button to add a style to the tableColumn
      - expected: custom style unchanged
      - actual: custom style vanished

      Reason: TableColumnHeader has a listener to the column's styleClass which overwrites any custom settings.

      import java.net.URL;

      //import de.swingempire.fx.utils.FXUtils;
      import javafx.application.Application;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      /**
       * TableColumnHeader: Custom styles are lost. Here the "custom" is
      * nested-column-header.
       *
       * @author Jeanette Winzenburg, Berlin
       */
      @SuppressWarnings({ "rawtypes", "unchecked" })
      public class BugColumnHeaderStyle extends Application {

          private Parent getContent() {
              TableView table = new TableView();
              TableColumn single = new TableColumn("Single");
              TableColumn nested = new TableColumn("Nested");
              TableColumn childOne = new TableColumn("Child One");
              TableColumn childTwo = new TableColumn("Child Two");
              nested.getColumns().addAll(childOne, childTwo);
              table.getColumns().addAll(single, nested);
              
              Button addStyle = new Button("add style to TableColumn");
              addStyle.setOnAction(e -> nested.getStyleClass().add("dummy"));
              BorderPane pane = new BorderPane(table);
              pane.setBottom(addStyle);
              return pane;
          }

          @Override
          public void start(Stage primaryStage) throws Exception {
              primaryStage.setScene(new Scene(getContent(), 600, 400));
              URL uri = getClass().getResource("headers.css");
              primaryStage.getScene().getStylesheets().add(uri.toExternalForm());
      // primaryStage.setTitle(FXUtils.version());
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      Content of headers.css:
      /**
       * Just want to see an effect, doesn't matter what
       */
      .nested-column-header > .nested-column-header {
      -fx-padding: 10;
      -fx-background-color: white;
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jgiles Jonathan Giles
                Reporter:
                fastegal Jeanette Winzenburg
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: