html 语言怎么改颜色代码,如何用代码更改颜色htmleditor?

我做了一个自定义的htmleditor扩展了htmleditor。

我去掉了一些按钮,又加了一些。

现在,我想添加几个按钮,将键入的文本更改为1种特定颜色。

但是我找不到一种方法来改变按钮的setOnAction中的文本颜色。

我试过两种方法。

1:在光标位置插入的HTML

2:设置HTML编辑器颜色的颜色选取器

(jscodeinserthtml字符串允许在光标处使用HTML)

String jsCodeInsertHtml = "function insertHtmlAtCursor(html) {\n" +

" var range, node;\n" +

" if (window.getSelection && window.getSelection().getRangeAt) {\n" +

" range = window.getSelection().getRangeAt(0);\n" +

" node = range.createContextualFragment(html);\n" +

" range.insertNode(node);\n" +

" } else if (document.selection && document.selection.createRange) {\n" +

" document.selection.createRange().pasteHTML(html);\n" +

" }\n" +

"}insertHtmlAtCursor('####html####')";

// add a custom button to the top toolbar.

Node nodetop = editor.lookup(".top-toolbar");

if (nodetop instanceof ToolBar) {

ToolBar topbar = (ToolBar) nodetop;

//var1 color

ImageView graphic = new ImageView(var1pic);

Button colorVar1Button = new Button("", graphic);

colorVar1Button.setFocusTraversable(false);

colorVar1Button.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent arg0) {

WebView webView=(WebView)editor.lookup("WebView");

WebEngine engine= webView.getEngine();

//try 1

engine.executeScript(jsCodeInsertHtml.replace("####html####","

"));

//the HTML is inserted , but no colorchange. i tryed some htmlvariants aswel

//try 2

Node color = editor.lookup(".html-editor-foreground");

((ColorPicker)color).setValue(Color.rgb(200,200,200));

// i notice the button change in the colorpicker ,

// but no change in color happens

topbar.getItems().addAll(colorVar1Button);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例代码,演示了如何在 ExtJS 表单中集成 layui 富文本编辑器: ``` Ext.define('MyApp.view.MyFormPanel', { extend: 'Ext.form.Panel', xtype: 'myformpanel', requires: [ 'Ext.form.field.Text', 'Ext.form.field.Checkbox', 'Ext.form.field.ComboBox', 'Ext.form.field.HtmlEditor', 'Ext.layout.container.Form' ], layout: 'form', items: [ { xtype: 'textfield', fieldLabel: 'Title', name: 'title', allowBlank: false }, { xtype: 'checkbox', fieldLabel: 'Is Active', name: 'isActive', inputValue: true }, { xtype: 'combobox', fieldLabel: 'Category', name: 'category', store: ['Category 1', 'Category 2', 'Category 3'] }, { xtype: 'htmleditor', fieldLabel: 'Content', name: 'content', enableColors: false, enableAlignments: false, enableFontSize: false, enableFont: false, enableLinks: false, enableLists: false, enableSourceEdit: false, listeners: { afterrender: function(editor) { layui.use('layedit', function(){ var layedit = layui.layedit; layedit.build(editor.getEl().down('iframe').dom, { tool: [ 'strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right', 'link' ] }); }); } } } ] }); ``` 在上面的代码中,我们使用了 ExtJS 的表单组件,并将 layui 的富文本编辑器集成到了 ExtJS 的表单中。在 htmleditor 组件的 `afterrender` 事件中,我们使用了 layui 的 `layedit.build` 方法来初始化 layui 富文本编辑器。我们可以通过配置 `tool` 属性来指定需要显示的工具栏按钮。 请注意,这只是一个示例代码,你需要根据自己的实际情况进行修
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值