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

Methods for checking focus "inside" a node

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 8u20
    • javafx
    • None

      When writing custom controls the skins often consist of one or more standard controls. These controls will have the focus when the user performs an edit (e.g. inside a TextField). However, the application using the custom control will not "see" the textfield but only the custom control. It would be good if methods were added to Node that would allow the application to check if something inside a node / parent currently has the focus.

      Example:

      public boolean hasFocus() {
      if (isFocused()) {
      return true;
      }
      for (Node c : getChildren()) {
      if (c.isFocused()) {
      return true;
      }
      if (c instanceof Parent) {
      boolean internalFocus = isFocusInside((Parent) c);
      if (internalFocus) {
      return true;
      }
      }
      }
      return false;
      }

      private boolean isFocusInside(Parent p) {
      for (Node c : getChildren()) {
      if (c.isFocused()) {
      return true;
      }
      if (c instanceof Parent) {
      boolean internalFocus = isFocusInside((Parent) c);
      if (internalFocus) {
      return true;
      }
      }
      }
      return false;
      }

            Unassigned Unassigned
            dlemmermajfx Dirk Lemmermann (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: