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

[SwingNode]:swing component in swingnode lost foucs when keycode up(Arrow Up)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u5
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
      None

      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

        Attachments

          Activity

            People

            Assignee:
            anthony Anthony Petrov (Inactive)
            Reporter:
            hgreenjfx Herry Green (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: