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

Webview with contenteditable cannot be focused programmatically

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • fx2.1
    • javafx
    • None
    • Windows 7, Netbeans 7.1.1

    • web

      Trying to do a requestFocus() on the WebView does not work until the user has first clicked on the control.
      I know this must be possible as htmlEditor can be focused this way (and I suspect it is based on a contenteditable WebView).

      I am coding my own specialized htmlEditor using a webview with "contenteditable" and I would really like to be able to focus it like I can do with the standard htmlEditor.

      Example code to reproduce the issue:

      public class WebViewConteneditableDemo extends Application {
          /**
           * Initial editor content
           */
          String initialEditview = "<html><head>"
                  + "</head><body bgcolor = 'lightgrey' contenteditable='true'>"
                  +"</body></html>";
          
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
              primaryStage.setTitle("Webview focus demo");
              
              
              final WebView editor = new WebView();
              
              Button btn = new Button();
              btn.setText("Test Webview focus");
              btn.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent event) {
                     editor.requestFocus();
                  }
              });
              
              BorderPane root = new BorderPane();
              root.setTop(btn);
              
              root.setCenter(editor);
              editor.getEngine().loadContent(initialEditview);
              
              primaryStage.setScene(new Scene(root, 500, 450));
              primaryStage.show();
          }
      }

            peterz Peter Zhelezniakov
            enriquejfx Enrique (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: