JavaFX HTMLEditor

104 篇文章 5 订阅

The JavaFX HTMLEditor is an advanced HTML editor that enables the user to edit HTML easier than by writing the full HTML markup in text. The HTMLEditor contains a set of buttons that can be used to set the styles of the edited text WYSIWYG style. The JavaFX HTMLEditor is represented by the class javafx.scene.web.HTMLEditor. Here is a screenshot of a JavaFX HTMLEditor:

Full HTMLEditor Example

Here is first a full JavaFX HTMLEditor example so you can see what using the HTMLEditor looks like in code:

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

public class HtmlEditorExample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) {

        HTMLEditor htmlEditor = new HTMLEditor();

        VBox vBox = new VBox(htmlEditor);
        Scene scene = new Scene(vBox);

        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX App");

        primaryStage.show();
    }
}

Create an HTMLEditor

Before you can use a JavaFX HTMLEditor in your code, you must first create an instance of it. Here is an example of creating an instance of a JavaFX HTMLEditor:

 HTMLEditor htmlEditor = new HTMLEditor();

Get HTML From HTMLEditor

Sooner or later you will probably want to obtain the HTML text that was edited in the HTMLEditor by the user. You obtain the HTML from the HTMLEditor via its getHtmlText() method. Here is an example of getting the HTML from a JavaFX HTMLEditor instance:

String htmlText = htmlEditor.getHtmlText();

As you can see, the HTML is returned as a standard Java String.

Set HTML in HTMLEditor

You can also set the HTML to be edited in a JavaFX HTMLEditor via its setHtmlText() method. Here is an example of setting the HTML to be edited in a JavaFX HTMLEditor instance:

String htmlText = "<b>Bold text</b>";

htmlEditor.setHtmlText(htmlText);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值