TableView does not show horizontal scrollbar when there is no data

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P5
    • tbd
    • Affects Version/s: 7u45, 8
    • Component/s: javafx
    • Environment:

      Windows, Linux javafx2.2.45, javafx8

      I add empty TableView with column resize policy set to TableView.UNCONSTRAINED_RESIZE_POLICY to Scene. When all columns are visible, there is no horizontal scroll bar (it's right), but when i resize main window and not all columns are visible, there is no horizontal scroll bar too, i think it shouldn't be so, and horizontal scroll bar should be visible.
      If table is not empty there is horizontal scroll bar when not all columns are visible. If i remove all rows, horizontal scroll bar disappears.
      Analog bug was in qt qml tableview and it was fixed.

      Here is an example:

      import java.util.ArrayList;

      import javafx.application.Application;
      import javafx.beans.property.SimpleBooleanProperty;
      import javafx.beans.property.SimpleDoubleProperty;
      import javafx.beans.property.SimpleIntegerProperty;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.TableColumn.SortType;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Priority;
      import javafx.scene.layout.RowConstraints;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class MainWindowFX extends Application {

      @Override
      public void start(Stage primaryStage) throws Exception {
      primaryStage.setTitle("Hello World!");

      Button b = new Button("Add");
      Button b1 = new Button("Del");

      final TableView<Test> table = new TableView<>();

      table.setEditable(true);
      table.setTableMenuButtonVisible(true);

      final TableColumn<Test, Number> c1 = new TableColumn<>("ID");
      c1.setCellValueFactory(new PropertyValueFactory<Test, Number>("id"));

      final TableColumn<Test, String> c2 = new TableColumn<>("Name");
      c2.setCellValueFactory(new PropertyValueFactory<Test, String>("name"));

      TableColumn<Test, Number> c3 = new TableColumn<>("Price");
      c3.setCellValueFactory(new PropertyValueFactory<Test, Number>("price"));

      TableColumn<Test, Boolean> c4 = new TableColumn<>("Is");
      c4.setCellValueFactory(new PropertyValueFactory<Test, Boolean>("is"));

      table.setSortPolicy(new Callback<TableView<Test>, Boolean>() {
      @Override
      public Boolean call(TableView<Test> param) {
      for (TableColumn<Test, ?> tc : param.getSortOrder()) {
      if (tc == c2) {
      return false;
      }
      }
      return TableView.DEFAULT_SORT_POLICY.call(param);
      }
      });
      table.getColumns().addAll(c1, c2, c3, c4);

      final ObservableList<Test> data = FXCollections.observableList(new ArrayList<Test>());
      table.setItems(data);

      table.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

      c1.setSortType(SortType.ASCENDING);
      table.getSortOrder().add(c1);

      b.setOnAction(new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent event) {
      int MAXN = 10;// 2000000;
      ArrayList<Test> list = new ArrayList<>(MAXN);
      for (int i = 0; i < MAXN; i++) {
      Test tmp = new Test(i, Integer.toString(i), i, (i % 2 == 0) ? (false) : (true));
      list.add(i, tmp);
      }
      data.addAll(list);
      c1.setPrefWidth(100);

      table.sort();
      }
      });
      b1.setOnAction(new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent event) {
      table.getItems().remove(0);
      }
      });

      GridPane root = new GridPane();
      ColumnConstraints column1 = new ColumnConstraints();
      column1.setHgrow(Priority.ALWAYS);
      root.getColumnConstraints().addAll(column1);
      RowConstraints row1 = new RowConstraints();
      row1.setVgrow(Priority.ALWAYS);
      root.getRowConstraints().addAll(row1);
      root.add(table, 0, 0);

      HBox h = new HBox();
      h.setAlignment(Pos.CENTER_RIGHT);
      h.getChildren().add(b);
      h.getChildren().add(b1);
      root.add(h, 0, 1);

      primaryStage.setScene(new Scene(root, 500, 600));
      primaryStage.show();
      }

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

      public static class Test {
      private final SimpleIntegerProperty id = new SimpleIntegerProperty(0);
      private final SimpleStringProperty name = new SimpleStringProperty("");
      private final SimpleDoubleProperty price = new SimpleDoubleProperty(0);
      private final SimpleBooleanProperty is = new SimpleBooleanProperty(false);

      private Test() {}

      private Test(int id, String name, double price, boolean is) {
      this.id.set(id);
      this.name.set(name);
      this.price.set(price);
      this.is.set(is);
      }

      public int getId() {
      return id.get();
      }

      public void setId(int id) {
      this.id.set(id);
      }

      public String getName() {
      return name.get();
      }

      public void setName(String name) {
      this.name.set(name);
      }

      public double getPrice() {
      return price.get();
      }

      public void setPrice(double price) {
      this.price.set(price);
      }

      public boolean isIs() {
      return is.get();
      }

      public void setIs(boolean is) {
      this.is.set(is);
      }
      }
      }

      Resize window, so that not all columns are visible, there is no horizontal scroll bar, then click "add" button, and scroll bar will be shown.

            Assignee:
            Unassigned
            Reporter:
            Roman I. Liverovskiy (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Imported: