-
JTextPane 中如何设置背景颜色并得到html代码?0
我在敲一个文本编辑器,用的是JTextPane,然后发现StyledEditorKit下面并没有设置背景色的方法。
后来我用这样的方法来设置背景色SimpleAttributeSet aSet = new SimpleAttributeSet(); StyleConstants.setBackground(aSet, color); StyledDocument doc = textPane.getStyledDocument(); doc.setCharacterAttributes(textPane.getSelectionStart(),textPane.getSelectionEnd()- textPane.getSelectionStart(), aSet, false);
这样的是能够显示出来效果,但是并不能通过textPane.getText();的方式得到html代码。
本来我还看到一个方式说是可以得到:class bgAction extends StyledEditorKit.StyledTextAction { public bgAction(String arg0) { super(arg0); // TODO Auto-generated constructor stub } @Override public void actionPerformed(ActionEvent arg0) { JEditorPane editor = getEditor(arg0); try { String selectedText = editor.getSelectedText(); HTMLDocument document = (HTMLDocument) this.getStyledDocument(editor); System.out.println(document == TextView.this.document); document.remove(editor.getSelectionStart(),selectedText.length()); HTMLEditorKit et = (HTMLEditorKit) this.getStyledEditorKit(editor); et.insertHTML(document, editor.getSelectionStart(), ""+ selectedText + "", 0, 0, HTML.Tag.SPAN); } catch (Exception ex) { ex.printStackTrace(); } } }
但是insertHTML方法好像没有用似的,难道我哪里出错了吗?
所以我想在这里问下,能不能有个方式设置JTextPane中的背景色并且得到html代码。
问题补充:为什么没有人回答啊!2013年7月31日 10:09
目前还没有答案
相关推荐
JAVA-----JTextPane实例 代码
SWT JTextPane 可以把控件中需要的字符串的颜色修改成自己想要的颜色
JTextPane使用,可以传图片,文字等
NULL 博文链接:https://icarusliu.iteye.com/blog/1412007
演示、说明程序 博文链接:https://bps.iteye.com/blog/136627
本源码实现了 文本区里加图片和插入艺术字的功能 窗口使用Windows窗体风格
NULL 博文链接:https://icarusliu.iteye.com/blog/2098986
Java制作的网页浏览器和源代码查看器,仿IE的网页浏览功能,不支持HTML5,窗口采用上下分屏显示的方式,上面显示网页浏览器,下面显示该网页的源代码,JTextField jtfAddress; //输入html文件地址或网址 ...
NULL 博文链接:https://gh0769.iteye.com/blog/598839
课程设计期间做的Java的桌面端小程序,可以发送Emoji表情的聊天室,另外在文件夹中放置了自己的关键代码部分解析,关于emoji部分可查看笔者博客https://blog.csdn.net/qq_38853759/article/details/88657230?...
老师给的例子,实现了字体设置。使用了JTextPane,主要还是一个实现设置字体的例子
Java代码编写的简单网页浏览器,仿IE基础功能,只能解析标准的HTML文件,现在流行的HTML5格式不能解析。使用方法:可直接输入文件名或网络地址,但必需事先连入网络。 JTextField jtfAddress; //输入html文件地址...
1、(BufferedReader)读文字的速度非常慢~~~~~10M左右的东西要30秒到1分钟,如何提高文字读取的速度——一部分一部分的读也行 ...怎么现在用JTextPane标记的文字的颜色消失了? yujinlong0001@sina.com
java文本设计 实用代码import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing....