插入位置到JEditorPane的html中 [英] caret position into the html of JEditorPane

查看:125
本文介绍了插入位置到JEditorPane的html中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JEditorPane的getCaretPosition方法仅为html控件的文本部分提供索引。是否有可能将索引放入html文本?

The getCaretPosition method of JEditorPane gives an index into the text only part of the html control. Is there a possibility to get the index into the html text?

更具体地说,假设我有一个html文本(其中|表示插入位置)

To be more specific suppose I have a html text (where | denotes the caret position)

abcd<img src="1.jpg"/>123|<img src="2.jpg"/>

现在getCaretPosition给出8而我需要25才能读出图像的文件名。

Now getCaretPosition gives 8 while I would need 25 as a result to read out the filename of the image.

推荐答案

我认为您不能将您的插入符号转换为能够将标记计为字符。如果你的最终目的是读取图像文件名,你应该使用:

I don't think you can transform your caret to be able to count tags as characters. If your final aim is to read image filename, you should use :

HTMLEditorKit (JEditorPane.getEditorKitForContentType("text/html") );

有关利用率的更多信息,请参阅 Oracle HTMLEditorKit文档 O'Reilly PDF ,其中包含有趣的示例。

For more information about utilisation see Oracle HTMLEditorKit documentation and this O'Reilly PDF that contains interesting examples.

这篇关于插入位置到JEditorPane的html中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆