How to hide the controls of HTMLEditor?

前端 未结 10 700
日久生厌
日久生厌 2020-12-10 12:45

is it possible to hide the controls of a HTMLEditor above the actual text? (Alignment, Copy&Paste icons, stylings etc.)

Thanks for any help

10条回答
  •  再見小時候
    2020-12-10 13:25

    If you use unsupported methods, you can customize the toolbars pretty easily.

    As Uluk states in his answer, the methods below aren't officially supported.

    import java.util.regex.Pattern;
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.image.ImageView;
    import javafx.scene.web.HTMLEditor;
    import javafx.stage.Stage;
    
    public class HTMLEditorSample extends Application {
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        final HTMLEditor htmlEditor = new HTMLEditor();
        stage.setScene(new Scene(htmlEditor));
        stage.show();
    
        hideImageNodesMatching(htmlEditor, Pattern.compile(".*(Cut|Copy|Paste).*"), 0);
        Node seperator = htmlEditor.lookup(".separator");
        seperator.setVisible(false); seperator.setManaged(false);
      }
    
      public void hideImageNodesMatching(Node node, Pattern imageNamePattern, int depth) {
        if (node instanceof ImageView) {
          ImageView imageView = (ImageView) node;
          String url = imageView.getImage().impl_getUrl();
          if (url != null && imageNamePattern.matcher(url).matches()) {
            Node button = imageView.getParent().getParent();
            button.setVisible(false); button.setManaged(false);
          }
        }
        if (node instanceof Parent) 
          for (Node child : ((Parent) node).getChildrenUnmodifiable()) 
            hideImageNodesMatching(child, imageNamePattern, depth + 1);
      }
    }
    

提交回复
热议问题