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

[TableView] Table content does not sort again after changing the data set

XMLWordPrintable

      1. Fill a table with random sortable data
      2. Click a header of the table/column to sort them
      3. Fill the table again using the setItems() method
      4. The header keeps displaying an arrow indicating the way the data are supposed to be ordered but they aren't.

      Code to reproduce the issue:

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.value.ObservableValue;
      import javafx.collections.FXCollections;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.TableColumn.CellDataFeatures;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class Test3 extends Application
      {
      public static void main(String[] args)
      {
      launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception
      {
      final TableColumn<String, String> column = new TableColumn<String, String>("Click to sort");
      column.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<String,String>, ObservableValue<String>>()
      {
      @Override
      public ObservableValue<String> call(CellDataFeatures<String, String> param)
      {
      return new SimpleStringProperty(param.getValue());
      }
      });

      final TableView<String> table = new TableView<String>();
      table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
      table.getColumns().add(column);

      final Button button = new Button("Fill table");

      final VBox vbox = new VBox(10.0, table, button);
      vbox.setPadding(new Insets(10.0));

      primaryStage.setScene(new Scene(vbox));
      primaryStage.show();

      button.onActionProperty().set(new EventHandler<ActionEvent>()
      {
      @Override
      public void handle(ActionEvent event)
      {
      table.setItems(FXCollections.observableArrayList("s", "o", "r", "t", "m", "e"));
      }
      });
      }
      }

            jgiles Jonathan Giles
            jsmucrjfx Jan Smucr (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: