繁体   English   中英

如何获取HTMLEditor,JavaFX中的节点ID

[英]How to get the IDs of nodes inside HTMLEditor, JavaFX

我希望从HTMLEditor中删除一些控制按钮,因为我不需要它们。 为此,我需要到达所需的节点。 我怎么知道HTMLEditor里面的节点ID? 请参阅以下内容。 谢谢!

public class myApp extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("myApp.fxml")); //this fxml has HTMLEditor named htmlEditor.
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();

        Node someControlInsideHtmlEditor = root.lookup("#htmlEditor").lookup("#what_Is_The_ID_of_This_someControlInsideHtmlEditor")
    }
}

  • 这里下载Scenic View
  • 将其添加到应用程序的类路径中
  • 将以下行添加到start()方法的结尾:

    ScenicView.show(场景);

  • 运行该应用程序
  • 将弹出两个窗口:带有HTMLEditor和Scenic View的Stage的primaryStage
现在,您可以访问场景图的每个节点。 在左窗格中打开树,然后从HTMLEditor中选择一个节点。 您可以通过CSS类访问控件。

例如,打开HTMLEditor - > ToolBar - > HBox,然后选择第一个Button。 查看右侧“节点详细信息”中的“styleClass”。 你需要“html-editor-cut”。 它可以与此代码一起使用:

Button cutButton =(Button)root.lookup(“。html-editor-cut”);

不知道你是否还在寻找这个答案。 在Java 8中,HTMLEditor只有一个子节点,它是一个GridPane。 前两个孩子是ToolBars,第三个是WebView。 从网格窗格中删除前两个子项以执行所需的格式设置。 这有帮助吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM