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

[TableView] Empty TableView doesn't show scroll bars so column headers on the right aren't visible

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 9
    • 7u45, 8
    • javafx
    • All

      The code below displays a TableView with 20 columns. The columns don't fit on the screen so I would expect a horizontal scroll bar to be displayed. It is not. If I add some items to the TableView then the scroll bar is displayed as expected.

      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyStringWrapper;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      import java.util.ArrayList;
      import java.util.List;

      public class ManyColumnsTest extends Application {
          @Override
          public void start(Stage stage) throws Exception {
              BorderPane pane = new BorderPane();
              Scene scene = new Scene(pane, 500, 500);
              stage.setScene(scene);

              int numColumns = 20;
              TableView<String[]> table = new TableView<>();
              for (int i = 0; i < numColumns; i++) {
                  final int column = i;
                  TableColumn<String[], String> childColumn = new TableColumn<>("Child Column " + i);
                  childColumn.setCellValueFactory(stringCellDataFeatures -> new ReadOnlyStringWrapper(stringCellDataFeatures.getValue()[column]));
                  table.getColumns().add(childColumn);
              }
              List<String[]> data = new ArrayList<>(5);
              for (int j = 0; j < 5; j++) {
                  String[] row = new String[numColumns];
                  for (int i = 0; i < numColumns; i++) {
                      row[i] = "(" + j + ", " + i + ")";
                  }
                  data.add(row);
              }
      // table.setItems(FXCollections.observableArrayList(data));

              pane.setCenter(table);
              stage.show();
          }

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

            jgiles Jonathan Giles
            ndarcy Nick D'Arcy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: