Javafx从htmleditor中删除节点

Han*_*gan 1 html css java javafx

我有一个在javafx中开发的简单应用程序.问题是我想删除两个工具栏但却找不到如何做到这一点.在代码中,我将底部工具栏的可见性设置为false.如果您需要回答以获取帮助:顶部工具栏的ID是.top-toolbar,而底部工具栏的ID是.bottom-toolbar.非常感谢您的帮助......这是我的代码.提前致谢.

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class PrivateHistory extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("HTMLEditor Sample");
        stage.setWidth(400);
        stage.setHeight(300);   
        final HTMLEditor htmlEditor = new HTMLEditor();
        htmlEditor.setPrefHeight(245);
        Scene scene = new Scene(htmlEditor);
        stage.setScene(scene);
        Node node = htmlEditor.lookup(".bottom-toolbar");
        node.setVisible(false);
        //htmlEditor.setHtmlText("<img src='"+getClass().getResource("ball.png")+"' />");
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
} 
Run Code Online (Sandbox Code Playgroud)

Muh*_*mad 8

将以下代码应用于您的 htmlEditor

    htmlEditor.lookup(".top-toolbar").setManaged(false);
    htmlEditor.lookup(".top-toolbar").setVisible(false);

    htmlEditor.lookup(".bottom-toolbar").setManaged(false);
    htmlEditor.lookup(".bottom-toolbar").setVisible(false);
Run Code Online (Sandbox Code Playgroud)