当前位置: 首页 > news >正文

第三百七十二节 JavaFX教程 - JavaFX HTMLEditor

JavaFX教程 - JavaFX HTMLEditor

HTMLEditor控件是一个富文本编辑器,具有以下功能。

  • 粗体
  • 斜体
  • 下划线
  • 删除线
  • 字体系列
  • 字体大小
  • 前景色
  • 背景颜色
  • 缩进
  • 项目符号列表
  • 编号列表
  • 对齐
  • 水平线
  • 复制文本片段
  • 粘贴文本片段

HTMLEditor类返回HTML字符串中的编辑内容。

创建HTML编辑器

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

public class Main extends Application {
 
    @Override
    public void start(Stage stage) {
        HTMLEditor htmlEditor = new HTMLEditor();
        htmlEditor.setPrefHeight(245);
        Scene scene = new Scene(htmlEditor);       
        stage.setScene(scene);
        stage.show();
    } 
    public static void main(String[] args) {
        launch(args);
    }
}

上面的代码生成以下结果。

null

HTML内容

要将内容设置为HTMLEditor类,请使用setHtmlText方法。

htmlEditor.setHtmlText(INITIAL_TEXT);
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class Main extends Application {
 
    @Override
    public void start(Stage stage) {
        HTMLEditor htmlEditor = new HTMLEditor();
        htmlEditor.setPrefHeight(245);
        String INITIAL_TEXT = "Lorem ipsum dolor sit "
            + "amet, consectetur adipiscing elit. Nam tortor felis, pulvinar "
            + "aliquam sagittis gravida eu dolor. Etiam sit amet ipsum "
            + "sem.";
        htmlEditor.setHtmlText(INITIAL_TEXT);
        Scene scene = new Scene(htmlEditor);       
        stage.setScene(scene);
        stage.show();
    } 
    public static void main(String[] args) {
        launch(args);
    }
}

上面的代码生成以下结果。

null

格式

我们可以使用此字符串中的HTML标记为最初渲染的内容应用特定的格式。

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

public class Main extends Application {
 
    @Override
    public void start(Stage stage) {
        HTMLEditor htmlEditor = new HTMLEditor();
        htmlEditor.setPrefHeight(245);
        String INITIAL_TEXT = "Lorem ipsum dolor sit "
            + "amet, consectetur adipiscing elit. <i>Nam tortor felis</i>, pulvinar "
            + "<UL><li>a</li><li>a</li><li>a</li></UL>"
            + "aliquam sagittis gravida <b>eu dolor</b>. Etiam sit amet ipsum "
            + "sem.";
        htmlEditor.setHtmlText(INITIAL_TEXT);
        Scene scene = new Scene(htmlEditor);       
        stage.setScene(scene);
        stage.show();
    } 
    public static void main(String[] args) {
        launch(args);
    }
}

上面的代码生成以下结果。

null

获取HTML内容

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class Main extends Application {
 
    @Override
    public void start(Stage stage) {
        HTMLEditor htmlEditor = new HTMLEditor();
        htmlEditor.setPrefHeight(245);
        String INITIAL_TEXT = "Lorem ipsum dolor sit "
            + "amet, consectetur adipiscing elit. <i>Nam tortor felis</i>, pulvinar "
            + "<UL><li>a</li><li>a</li><li>a</li></UL>"
            + "aliquam sagittis gravida <b>eu dolor</b>. Etiam sit amet ipsum "
            + "sem.";
        htmlEditor.setHtmlText(INITIAL_TEXT);
        
        Button showHTMLButton = new Button("Produce HTML Code");
        
        showHTMLButton.setOnAction((ActionEvent arg0) -> {
          System.out.println(htmlEditor.getHtmlText());
        });
        
        VBox vbox = new VBox();
        vbox.getChildren().addAll(htmlEditor,showHTMLButton);
        Scene scene = new Scene(vbox);       
        stage.setScene(scene);
        stage.show();
    } 
    public static void main(String[] args) {
        launch(args);
    }
}

上面的代码生成以下结果。

null


文章转载自:

http://DHPRGzxA.xswrb.cn
http://KtwA0Jzw.xswrb.cn
http://OBK8HjiV.xswrb.cn
http://sSG2pS53.xswrb.cn
http://BdYTGpQl.xswrb.cn
http://esrO40I6.xswrb.cn
http://xGaIjbyD.xswrb.cn
http://SOXdqQ4K.xswrb.cn
http://SgvJ7C8C.xswrb.cn
http://mwWiToWg.xswrb.cn
http://rO5Mke6Q.xswrb.cn
http://OeNMOPKn.xswrb.cn
http://jvq39AIH.xswrb.cn
http://NZ3tv1Mb.xswrb.cn
http://gncTyIaN.xswrb.cn
http://xRey6FKs.xswrb.cn
http://D1bc1I1F.xswrb.cn
http://uNiQtOda.xswrb.cn
http://fuFGuF7o.xswrb.cn
http://u76tPT2y.xswrb.cn
http://ZyJt7YHo.xswrb.cn
http://gOzUwfTM.xswrb.cn
http://mj12VeiW.xswrb.cn
http://RBkKcbd3.xswrb.cn
http://oss0U0mB.xswrb.cn
http://1fbDQEqK.xswrb.cn
http://sFrtyj1b.xswrb.cn
http://NfzL5fHj.xswrb.cn
http://wAw6RAgS.xswrb.cn
http://F0KICehN.xswrb.cn
http://www.dtcms.com/a/47297.html

相关文章:

  • spring事件
  • 【推荐项目】023-游泳俱乐部管理系统
  • 优博讯,蓝禾,三七互娱,顺丰,oppo,游卡,汤臣倍健,康冠科技,作业帮,高途教育25届春招内推
  • 基于 Python 深度学习的电影评论情感分析可视化系统(2.0 全新升级)
  • 算法日常刷题笔记(3)
  • 【Java项目】基于SpringBoot的藏区特产销售平台
  • 目标检测算法——YOLOV11——算法详解
  • 【考试大纲】中级网络工程师考试大纲(最新版与旧版对比)
  • 斐波那契数列的可视化
  • Linux tar命令
  • DOM HTML:深入理解与高效运用
  • 基于Spring Boot + Vue的常规应急物资管理系统设计与实现
  • C++ 循环结构练习题目集
  • 计算机面试项目经历描述技巧
  • 从浏览器地址栏输入URL到页面加载发生了什么?
  • apload-lab打靶场
  • 视觉图像坐标转换
  • 影刀RPA开发拓展--SQL常用语句全攻略
  • Linux内核配置与构建原理
  • 大摩闭门会:250228 学习总结报告
  • 算法-二叉树篇27-把二叉搜索树转换为累加树
  • el-input实现金额输入
  • TaskBuilder查看和预览客户信息列表页面
  • smolagents学习笔记系列(九)Examples - Orchestrate a multi-agent system
  • 15. C++多线程编程-网络编程-GUI编程(如Qt)学习建议
  • Linux安装jdk,node,mysql,redis
  • 最佳Nginx日志分割
  • InterHand26M(handposeX-json 格式)数据集-release >> DataBall
  • DAV_postgresql_3-schema
  • 初识MySQL · 数据库