This discussion is archived
7 Replies Latest reply: Feb 20, 2013 12:23 PM by Pitt RSS

Setting the Navigation Sequence of Text Fields

jtblair Newbie
Currently Being Moderated
I have built an application that is made up of a single page with about 15 text fields on it. For some reason, when I run the application (from within NetBeans) the Text Field navigation does not occur in the order they appear in the Hierarchy. Is there any way to control the navigation sequence.
Thanks,
Jerry
  • 1. Re: Setting the Navigation Sequence of Text Fields
    jsmith Guru
    Currently Being Moderated
    Unfortunately there is no high level functionality (like assigning a tab order ids to controls in fxml or having a having focusmodel implementation) that I know of (consider raising a jira request http://javafx-jira.kenai.com).

    There is a focusproperty on node, so you can add listeners to that property for the controls you are interested in and set the focus to the next control that you want the user to be able to navigate to (via the control.requestFocus() method) - not a great solution I know, so I'd be interested if anybody has a better one.
  • 2. Re: Setting the Navigation Sequence of Text Fields
    916123 Newbie
    Currently Being Moderated
    Actually, the tab order seems to track the order of the elements in the FXML. This is not necessarily the order perceived by the user, as the FXML can give a position for the first element on its list that puts it graphically below the second element, and so forth.

    If you're using Scene Builder you can just drag-and-drop elements in the Hierarchy view to change their order - it has no effect on their screen locations.

    Michael
  • 3. Re: Setting the Navigation Sequence of Text Fields
    Pitt Newbie
    Currently Being Moderated
    Excuse me, but isn't there any evolution for this ? It's a big problem for me and I think for many developpers, i'm forced to try to catch key events and consume them, it's really ugly...
  • 4. Re: Setting the Navigation Sequence of Text Fields
    jsmith Guru
    Currently Being Moderated
    It's not perfect and I can imagine some scenarios where it wouldn't work, but can you not use user 913120's solution for this?
    If not, what is specific about your case which prevents it from working and requires you to resort to catching and consuming key events?
  • 5. Re: Setting the Navigation Sequence of Text Fields
    Pitt Newbie
    Currently Being Moderated
    I don't use the Scene Builder, so I don't understand precisely how I could achieve without layout modifications.
    For example, when I've got a HBox with three buttons, I know that the focus will go from left to right, so when I want it from right to left I reach a limit, I need to change my layout, use a GridPane or so that allows me to write nodes in the right order in the FXML file. Or am I missing some point?
  • 6. Re: Setting the Navigation Sequence of Text Fields
    jsmith Guru
    Currently Being Moderated
    For example, when I've got a HBox with three buttons, I know that the focus will go from left to right, so when I want it from right to left I reach a limit, I need to change my layout, use a GridPane or so that allows me to write nodes in the right order in the FXML file. Or am I missing some point?
    Nope, you understand the point exactly.

    There is a FocusModel which may help in such situations, but there is no documentation on how it is intended to be used:
    http://docs.oracle.com/javafx/2/api/javafx/scene/control/FocusModel.html

    I believe (and I don't really know) the intent of the FocusModel is for internal use within custom controls, so you could define a custom control for your HBox + buttons and utilize a FocusModel internally to the control manage the focus. It is a rather heavy handed solution though and the APIs for defining custom controls aren't documented anyway.

    At this point, I'd go back to the original suggestion in this thread of raising a jira feature request against the runtime at:
    http://javafx-jira.kenai.com
    In the jira request link back to this thread and include a description of your use case.

    Probably it wouldn't be implemented until post JavaFX 8, which is unlikely to help you, but may help others in the future.
  • 7. Re: Setting the Navigation Sequence of Text Fields
    Pitt Newbie
    Currently Being Moderated
    Ok, thank you jsmith, I'll do that, hope someone will give some interest to it in the next few years ;)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points