3 Replies Latest reply: Apr 5, 2013 7:43 AM by James_D RSS

    JavaFX Rapid focus between controls


      Not sure how to adequately describe this.

      I have seen from time to time my application freeze - it goes into some state where the blue focus indicator rapidly toggles between controls such as text fields or combo boxes.

      I can reproduce it with Scene Builder :

      1) select a control in the builder
      2) go to the Keyboard section of Code
      3) click in the On Key Pressed combo box
      4) click into another application - your browser, Word, etc.
      5) click back into the scene builder, but into the On Key Released combox box field.

      On my computer - the focus indicator rapidly toggle back and forth between the OnKeyPressed and OnKeyReleased fields.

      This same thing happens occasionally in my application as well. It is like JavaFX is not sure what fields should have focus. The only way to get out of the application is to kill the process via the Task Manager.

      Is this a known issue?


      Edited by: Bluewizard on Apr 4, 2013 9:07 AM
        • 1. Re: JavaFX Rapid focus between controls
          I can reproduce this in JDK 1.7.0_17 (JavaFX 2.2.7) with the code below. The issue appears fixed in JDK 1.8.0 b_82.

          As in the original post, put focus on one combo box. Click outside the application. Then click on the other combo box.
          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.ComboBox;
          import javafx.scene.control.TextArea;
          import javafx.scene.layout.BorderPane;
          import javafx.scene.layout.HBox;
          import javafx.stage.Stage;
          public class ComboBoxFocusTest extends Application {
            public void start(Stage primaryStage) {
              final HBox combos = new HBox(15);
              final ComboBox<String> box1 = new ComboBox<>(
                  FXCollections.observableArrayList("Apples", "Oranges", "Pears"));
              final ComboBox<String> box2 = new ComboBox<>(
                  FXCollections.observableArrayList("Tea", "Coffee", "Hot Chocolate"));
              combos.getChildren().addAll(box1, box2);
              final BorderPane root = new BorderPane();
              root.setCenter(new TextArea());
              final Scene scene = new Scene(root, 600, 400);
              scene.focusOwnerProperty().addListener(new ChangeListener<Node>() {
                public void changed(ObservableValue<? extends Node> observable,
                    Node oldNode, Node newNode) {
                  System.out.println("Focus changed to " + newNode);
            public static void main(String[] args) {
          • 2. Re: JavaFX Rapid focus between controls
            Thanks for confirmation.

            It looks like setting the focus traversable flag to false helps.
            • 3. Re: JavaFX Rapid focus between controls
              Also see [url https://javafx-jira.kenai.com/browse/RT-26185]this JIRA. It's been fixed in JavaFX 8.0; it looks like the plan is to backport it to the next release of JavaFX 2.2 (due out imminently, apparently).