I'm developing a JavaFX client. It is a two-pane software. The left pane is a list that shows several applications (with different layouts) developed for the client (Application_1
, Application_2
, etc). The right pane is the place where the Application_N
is shown.
An application, that is shown in the right pane of the software, has the following java class hierarchy:
BorderPane -> Application
(application class developed by me).
The Application
class has a Node
attribute (Node
body;) which contains a form, and this form contains a Field
.
When the application is being displayed in the mentioned right pane It calls the method requestFocus()
, and this method (that is overwritten from the JavaFX Node
class) has the duty to request focus (using this time the original requestFocus()
method from the JavaFX Node
class) for the mentioned field.
This procedure works good. However, the problem is when I want to add a ScrollPane
that will contain the Node
body. It seems to be that the ScrollPane
is disallowing the request focus method to the field in the body.
The code written below is from Application.java
Node body;
body = getBody(); // getBody() builds the UI of this application
scrollPanel = new ScrollPane();
scrollPanel.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPanel.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPanel.setFitToWidth(true);
scrollPanel.setFitToHeight(true);
scrollPanel.getStyleClass().add("application");
scrollPanel.setContent(body);
this.setCenter(scrollPanel);
...
And now, when the application is going to be displayed it executes the code below:
public void create(){
requestFocus();
}
@Override
public void requestFocus(){
accountField.requestFocus(); //using the method from the JavaFX node class
}
I repeat that the problem is happening when I put the scroll pane in my hierarchy. I would be grateful if someone has a comment or solution to this. Thank you.
I find the scrollPane incomplete and bugged. At this stage, my solution was to copy openjfx ScrollPane[Behavior|Skin] sources and make the nescessary hacks in.
One done, you can alter the focus stealing behavior in ScrollPaneBehavior