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

Vai*_*aib 3 java javafx fxml

我希望从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")
    }
}
Run Code Online (Sandbox Code Playgroud)

hoa*_*at4 5

  • 这里下载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");