【问题标题】:JavaFX HTMLEditor - focus webView (TextArea)JavaFX HTMLEditor - 聚焦 webView (TextArea)
【发布时间】:2016-05-23 13:58:41
【问题描述】:

我使用 JavaFX HTMLEditor 组件创建了一个聊天,在发送消息后,编辑器不再聚焦,因为您按下了当前聚焦的发送按钮)。我想以某种方式集中编辑器,我已经用 Google 搜索过,但没有找到答案。

【问题讨论】:

    标签: java javafx webview focus


    【解决方案1】:

    试试这个

      WebView webView = (WebView) htmlEditor.lookup("WebView");
        ((HTMLBodyElementImpl) ((NodeListImpl) webView.getEngine().getDocument().getElementsByTagName("body")).item(0)).focus();
    

    除了焦点之外,您还可以设置和获取文本等等

    【讨论】:

      【解决方案2】:
        void editorWebViewRequestFocus()
        {
          final WebView view = (WebView) ((GridPane) ((HTMLEditorSkin) editor.getSkin()).getChildren().get( 0 )).getChildren().get( 2 );
      
          Platform.runLater( () ->
          {
            view.fireEvent( new MouseEvent( MouseEvent.MOUSE_PRESSED, 100, 100, 200, 200, MouseButton.PRIMARY, 1, false, false, false, false,
                false, false, false, false, false, false, null ) );
            editor.requestFocus();
            view.fireEvent( new MouseEvent( MouseEvent.MOUSE_RELEASED, 100, 100, 200, 200, MouseButton.PRIMARY, 1, false, false, false, false,
                false, false, false, false, false, false, null ) );
          } );
        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-18
        • 2014-06-16
        • 1970-01-01
        • 2015-05-16
        • 1970-01-01
        • 2019-06-30
        相关资源
        最近更新 更多