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

Keyboard Navigation and Scene.focusOwnerProperty

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 7u6
    • javafx
    • Mac OSX

      I see a strange intermediate focusOwner change when navigating with the keyboard. If you run this code snippet:
      package test;

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.collections.FXCollections;
      import javafx.scene.Node;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.control.SplitPane;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TestFocusNavigation extends Application {

      @Override
      public void start(Stage primaryStage) {
      SplitPane p = new SplitPane();
      p.getItems().add(new ListView<String>(FXCollections.observableArrayList("V1","V2","V3")));

      TabPane tab = new TabPane();

      {
      Tab t = new Tab();
      t.setText("T1");
      BorderPane content = new BorderPane();
      content.setTop(new TextField());
      content.setCenter(new TextField());
      t.setContent(content);
      tab.getTabs().add(t);
      }


      p.getItems().add(tab);

      Scene s = new Scene(p,400,400);
      s.focusOwnerProperty().addListener(new ChangeListener<Node>() {

      @Override
      public void changed(ObservableValue<? extends Node> observable, Node oldValue, Node newValue) {
      System.err.println("Focus shifted to: " + newValue);
      }
      });
      primaryStage.setScene(s);
      primaryStage.show();
      }

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

      and put the cursor into the first text-field in T1 and type SHIFT-TAB you'll the console holds the following lines:

      Focus shifted to: ListView[id=null, styleClass=list-view]
      Focus shifted to: TextField[id=null, styleClass=text-input text-field]
      Focus shifted to: ListView[id=null, styleClass=list-view]
      Focus shifted to: TabPane[id=null, styleClass=tab-pane]

      The intermediate "ListView" is not making any sense to me why does FX move the focus there at first? I need to track the current focused control in my application to scope keybindings, ... and this intermediate focus traversal is causing me some troubles. A workaround I found is to schedule a Runnable with Platform.runLater and rule out the intermediate focus-control but this looks like it might break anytime.

            jgiles Jonathan Giles
            tschindl Tom Schindl
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: