Description
There is a JTextArea in SwingNode,When we click the up arrow, the focus not move into the textarea up line,but to the javafx component textFieldUser.
public class TestArrowKeyLostFocus extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane borderPane = new BorderPane();
HBox hBox = new HBox(5);
Label labelServer = new Label("Server:");
TextField textFieldServer = new TextField("http://100.0.6.162");
Label labelUser = new Label("User:");
TextField textFieldUser = new TextField("root");
hBox.getChildren().addAll(labelServer, textFieldServer, labelUser, textFieldUser);
borderPane.setTop(hBox);
SwingNode swingNode = new SwingNode();
createSwingContent(swingNode);
borderPane.setCenter(swingNode);
Scene scene = new Scene(borderPane, 1200, 800);
primaryStage.setScene(scene);
primaryStage.show();
}
private void createSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel jPanel = new JPanel();
BorderLayout borderLayout = new BorderLayout();
jPanel.setLayout(borderLayout);
JTextArea textArea = new JTextArea(200, 300);
jPanel.add(textArea);
swingNode.setContent(jPanel);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
Change the SwingNode's class SwingKeyEventHandler line 825
from:
if (event.getCode() == KeyCode.LEFT ||
event.getCode() == KeyCode.RIGHT ||
event.getCode() == KeyCode.TAB)
{
event.consume();
}
to:
if (event.getCode() == KeyCode.LEFT ||
event.getCode() == KeyCode.RIGHT ||
event.getCode() == KeyCode.TAB ||
event.getCode() == KeyCode.UP ||
event.getCode() == KeyCode.DOWN)
{
event.consume();
}
will resolve it
public class TestArrowKeyLostFocus extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane borderPane = new BorderPane();
HBox hBox = new HBox(5);
Label labelServer = new Label("Server:");
TextField textFieldServer = new TextField("http://100.0.6.162");
Label labelUser = new Label("User:");
TextField textFieldUser = new TextField("root");
hBox.getChildren().addAll(labelServer, textFieldServer, labelUser, textFieldUser);
borderPane.setTop(hBox);
SwingNode swingNode = new SwingNode();
createSwingContent(swingNode);
borderPane.setCenter(swingNode);
Scene scene = new Scene(borderPane, 1200, 800);
primaryStage.setScene(scene);
primaryStage.show();
}
private void createSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel jPanel = new JPanel();
BorderLayout borderLayout = new BorderLayout();
jPanel.setLayout(borderLayout);
JTextArea textArea = new JTextArea(200, 300);
jPanel.add(textArea);
swingNode.setContent(jPanel);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
Change the SwingNode's class SwingKeyEventHandler line 825
from:
if (event.getCode() == KeyCode.LEFT ||
event.getCode() == KeyCode.RIGHT ||
event.getCode() == KeyCode.TAB)
{
event.consume();
}
to:
if (event.getCode() == KeyCode.LEFT ||
event.getCode() == KeyCode.RIGHT ||
event.getCode() == KeyCode.TAB ||
event.getCode() == KeyCode.UP ||
event.getCode() == KeyCode.DOWN)
{
event.consume();
}
will resolve it