【问题标题】:How to get the IDs of nodes inside HTMLEditor, JavaFX如何获取 HTMLEditor、JavaFX 中的节点 ID
【发布时间】:2013-12-28 04:28:48
【问题描述】:

我希望从 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")
    }
}

【问题讨论】:

  • 大家好!新年快乐!我希望再次提出同样的问题,因为没有人回答它。提前谢谢你。

标签: java javafx fxml


【解决方案1】:

  • here下载Scenic View
  • 将此添加到应用程序的类路径中
  • 将以下行添加到您的 start() 方法的末尾:

    ScenicView.show(场景);

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

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

Button cutButton = (Button) root.lookup(".html-editor-cut");

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我们不能通过调用“lookupall()”来访问其他孩子吗?
    猜你喜欢
    • 2014-12-14
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 2013-11-16
    相关资源
    最近更新 更多