B4J Question Node Focus?

dilettante

Active Member
Licensed User
Longtime User
Sorry if this duplicates another question, but I didn't find it.

Tab order seems to be a function of declaration sequence within the .fxml file, so I guess you can hack around in the raw XML to change it when needed. But figuring out what determines which Node gets focus when a Form is loaded & shown escapes me. The Oracle docs say:
When a Scene is created, the system gives focus to a Node whose focusTraversable variable is true and that is eligible to receive the focus, unless the focus had been set explicitly via a call to requestFocus().
So it seems to be "random" (even though consistent once a Form and View have been created), though the rules appear to vary from Form to Form. You almost have to add a requestFocus() call to every chunk of Form-initialization code in your programs.

One thing that appears to be true is that a TextField gets precedence over a Button, i.e. if you have one of each on a Layout the TextField will always have focus when the Form is loaded and shown.

This is probably more of a JavaFX issue than a B4J issue but they are hard to separate when you are using B4J. But to sum up, my question is:

Does anybody know where to find comprehensive rules regarding focus and how to manage it at design time?
 

BPak

Active Member
Licensed User
Longtime User
I know that you can drag and drop the Controls to different places in the Hierarchy Panel.
 
Upvote 0

dilettante

Active Member
Licensed User
Longtime User
Yes, I saw that and it works fine for the tab order, but I still can't make a Button have focus (even when first in the list) when the Form 1st opens without setting focus at runtime.

The first TextField always gets focus first.
 
Upvote 0
Top