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

Some navigation keys (pg-down/up, etc) donot work until TreeView/ListView/TableView item has both focus AND is selected

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: fx2.1, 7u6
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      JavaFX 2.1/2.2 32-bit, Windows 7 64-bit

      Description

      For some reason, when a TableView (etc) gets the focus initially (or by calling requestFocus()), it is not quite "fully" focused -- that is, it has focus, but nothing is selected.

      Now, cursor keys like up/down/end/home will all respond properly and make an item of the View go into focus+selected state.

      However, if you are in this initial state where there is only focus (and not selection), then keys like pg-up/pg-down donot respond... until you use atleast one of the cursor keys once (to get an item to be both focused and selected).

      Expected behaviour would be that pg-down/up always function, regardless of selection.

      Here's some code to help demonstrate the problem. Run it, and without using the cursor keys/tab key/mouse, try to navigate the view with pg-up/down.

      This may also be related to RT-19593 -- where the scroll wheel down does not respond initially (for Views that have disabled all animations/highlights)

      package hs.javafx;

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TablePosition;
      import javafx.scene.control.TableView;
      import javafx.scene.control.TextField;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class PgDownTableViewTest extends Application {

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

        @Override
        public void start(Stage primaryStage) throws Exception {
          VBox vbox = new VBox();
          final TableView<Person> tableView = new TableView<>();

          for(int i = 0; i < 100; i++) {
            tableView.getItems().add(new Person("John" + i, "Hendrikx" + i));
          }

          TableColumn<Person, String> firstColumn = new TableColumn<>("First name");
          TableColumn<Person, String> secondColumn = new TableColumn<>("Last name");
          firstColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
          secondColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
          tableView.getColumns().add(firstColumn);
          tableView.getColumns().add(secondColumn);

          final TextField textField1 = new TextField();
          final TextField textField2 = new TextField();

          vbox.getChildren().addAll(tableView, textField1, textField2);

          Scene scene = new Scene(vbox);

      // scene.focusOwnerProperty().addListener(new ChangeListener() {
      // @Override
      // public void changed(ObservableValue arg0, Object arg1, Object arg2) {
      // System.out.println(">>> focus : " +arg2);
      // }
      // });

          primaryStage.setScene(scene);

          primaryStage.show();

          // attempts at given proper focus...
          tableView.requestFocus();
          tableView.focusModelProperty().get().focus(new TablePosition(tableView, 0, firstColumn));
          tableView.focusModelProperty().get().focusBelowCell();
          tableView.selectionModelProperty().get().select(1);
        }

        public class Person {
          private StringProperty firstName;

          public Person(String firstName, String lastName) {
            setFirstName(firstName);
            setLastName(lastName);
          }

          public void setFirstName(String value) {
            firstNameProperty().set(value);
          }

          public String getFirstName() {
            return firstNameProperty().get();
          }

          public StringProperty firstNameProperty() {
            if(firstName == null) {
              firstName = new SimpleStringProperty(this, "firstName");
            }
            return firstName;
          }

          private StringProperty lastName;

          public void setLastName(String value) {
            lastNameProperty().set(value);
          }

          public String getLastName() {
            return lastNameProperty().get();
          }

          public StringProperty lastNameProperty() {
            if(lastName == null) {
              lastName = new SimpleStringProperty(this, "lastName");
            }
            return lastName;
          }
        }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jhendrikx John Hendrikx
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported: