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

[RTL] Arrow keys navigation doesn't respect TableView orientation

XMLWordPrintable

      When the scene root's orientation is set to RIGHT_TO_LEFT, arrow key navigation seems reversed (right arrow moves left and left arrow moves right).

      Apparently, this is not a TableView issue, but here is where I encountered it.

      Here is my SSCCE:

      import javafx.application.Application;
      import javafx.beans.property.BooleanProperty;
      import javafx.beans.property.SimpleBooleanProperty;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.geometry.NodeOrientation;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class SandBox extends Application {


          @Override
          public void start(Stage stage) throws Exception {
              ObservableList<Person> persons = FXCollections.observableArrayList();
              persons.add(new Person("Sami", "Haddad", false));
              persons.add(new Person("Ahmed", "Hasan", true));
              persons.add(new Person("Rami", "Kassar", true));
              persons.add(new Person("Nehad", "Hamad", false));
              persons.add(new Person("Jamal", "Raei", true));
              persons.add(new Person("Ameer", "Raji", true));
              persons.add(new Person("Tahseen", "Muhsen", true));

              TableView<Person> tableView = new TableView<>();
              tableView.setItems(persons);
              tableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
              tableView.getSelectionModel().setCellSelectionEnabled(true);

              TableColumn<Person, String> colFirstName = new TableColumn<>("First Name");
              colFirstName.setCellValueFactory(p -> p.getValue().firstName);
              colFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
              colFirstName.setOnEditCommit(event -> event.getTableView().getItems().get(event.getTablePosition().getRow()).firstName.set(event.getNewValue()));

              TableColumn<Person, String> colLastName = new TableColumn<>("Last Name");
              colLastName.setCellValueFactory(p -> p.getValue().lastName);
              colLastName.setCellFactory(TextFieldTableCell.forTableColumn());
              colLastName.setOnEditCommit(event -> event.getTableView().getItems().get(event.getTablePosition().getRow()).lastName.set(event.getNewValue()));

              TableColumn<Person, Boolean> colInvited = new TableColumn<>("Invited");
              colInvited.setCellValueFactory(p -> p.getValue().invited);
              colInvited.setCellFactory(javafx.scene.control.cell.CheckBoxTableCell.forTableColumn(colInvited));

              tableView.getColumns().addAll(colFirstName, colLastName, colInvited);
              tableView.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);

              stage.setTitle("TableView Selection Bug");
              stage.setScene(new Scene(new VBox(tableView)));
              stage.show();
          }

          class Person {
              public StringProperty firstName;
              public StringProperty lastName;
              public BooleanProperty invited;

              public Person() {
                  this.firstName = new SimpleStringProperty("");
                  this.lastName = new SimpleStringProperty("");
                  this.invited = new SimpleBooleanProperty(false);
              }

              public Person(String fname, String lname, boolean invited) {
                  this();
                  this.firstName.set(fname);
                  this.lastName.set(lname);
                  this.invited.set(invited);
              }
          }

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

      To reproduce the bug:
      Select a cell in the table view, then navigate cells using arrow keys.

            leifs Leif Samuelsson (Inactive)
            asulaimanjfx Anas H. Sulaiman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: