我希望从 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来自 here
- 将其添加到您的应用程序的类路径中
- 将以下行添加到您的 start() 方法的末尾:
ScenicView.show(scene);
- 运行应用程序
- 将弹出两个窗口:带有 HTMLEditor 的 primaryStage 和 Scenic View 的 Stage
例如打开HTMLEditor -> ToolBar -> HBox,选择第一个Button。查看右侧“节点详细信息”中的“styleClass”。您将需要“html-editor-cut”。它可以与此代码一起使用:
Button cutButton = (Button) root.lookup(".html-editor-cut");
关于java - 如何获取 HTMLEditor、JavaFX 中的节点 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20810995/