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

[TableView] TableView placeholder node can overwrite table header

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • 8u40
    • javafx
    • java version "1.8.0_40-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b09)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b13, mixed mode)

      In the application that I'm working on I noticed that the placeholder node in empty tables is overwriting the table headers, which looks a bit messy. It's a minor issue, because it only shows up if you alter the min height of the TableView, which we probably shouldn't be doing in our app. But in any case, I think the TableView component could be modified to handle this case more cleanly. Here is a test case to reproduce the issue - run it and try moving the slider up and down while the table has data in it, all is good. Now click the 'Clear' button (so the table displays "There is no data" as a placeholder) and move the slider up towards the top of the table. At the point where there isn't enough room to show the "There is no data" label, it begins to overlap the table headers. In my view, it should stop moving upwards once it reaches the top of the table content area.

      Comment out the line "table.setMinHeight(10);" to see that the behaviour is fine in the default case.

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Orientation;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.SplitPane;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;
       
      public class TableViewNoData2 extends Application {
       
          private TableView<Person> table;
          
          private final ObservableList<Person> data =
                  FXCollections.observableArrayList(
                  new Person("Jacob", "Smith", "jacob.smith@example.com"),
                  new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
                  new Person("Ethan", "Williams", "ethan.williams@example.com"),
                  new Person("Emma", "Jones", "emma.jones@example.com"),
                  new Person("Michael", "Brown", "michael.brown@example.com"));
       
          public static void main(String[] args) {
              launch(args);
          }
       
          @Override
          public void start(Stage stage) {
              table = new TableView<Person>();
              table.setPlaceholder(new Label("There is no data"));
              Scene scene = new Scene(new Group());
              stage.setTitle("TableView Selection");
              stage.setWidth(450);
              stage.setHeight(550);
              
              TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
              firstNameCol.setMinWidth(100);
              firstNameCol.setCellValueFactory(
                  new PropertyValueFactory<Person, String>("firstName"));
       
       
              TableColumn<Person,String> lastNameCol = new TableColumn<>("Last Name");
              lastNameCol.setMinWidth(100);
              lastNameCol.setCellValueFactory(
                  new PropertyValueFactory<Person, String>("lastName"));
       
              TableColumn<Person, String> emailCol = new TableColumn<>("Email");
              emailCol.setMinWidth(200);
              emailCol.setCellValueFactory(
                  new PropertyValueFactory<Person, String>("email"));
       
              table.setItems(data);
              table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
              
              table.setMinHeight(10);
        
              BorderPane lowerPane = new BorderPane();
              final Button clearButton = new Button("Clear");
              clearButton.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent e) {
                      data.clear();
                  }
              });
              lowerPane.setCenter(clearButton);
              SplitPane splitter = new SplitPane();
              splitter.orientationProperty().set(Orientation.VERTICAL);
              splitter.getItems().add(table);
              splitter.getItems().add(lowerPane);
       
              scene.setRoot(splitter);
              stage.setScene(scene);
              stage.show();
          }
       
      }

            Unassigned Unassigned
            dgilbertjfx David Gilbert (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported: