问题描述
尝试获取文本窗格中每行的起点和终点:文本窗格包含(注意目标是每行的结尾,不包括空格行):
Trying to get the start and end point of each line within a text pane:The text pane contains (note target is the end of each line not including the blank space line):
(空白行)MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDKVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAEALQEQQKKQQKQQKQQKKQQKKQQKKQQKQQKQQKQQKKMVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtargetMVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDDFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKDDDDDDDEEQNKEALQDVEDENQtarget
(blank space line)MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDKVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtargetMVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtargetMVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDDFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKDDDDDDDEEQNKEALQDVEDENQtarget
//这就是我所拥有的
Element root = jTextPane1.getDocument().getDefaultRootElement();
Element one = root.getElement(0);
while (one !=null){
int one1 = one.getStartOffset();
int two1 = one.getEndOffset();
System.out.println(one1);
System.out.println(two1);
one = root.getElement(two1);
}
这是我得到的(第一个和第二个元素),然后挂起:01个1个232
This is what I get (1st and 2nd element) and then hangs:011232
推荐答案
您可以混合使用模型和视图. Document
只是模型,但行数取决于视图(内容的宽度).
You mix model and view. Document
is just model but amount of rows depends on view (width of content).
使用javax.swing.text.Utilities.getRowStart()/getRowEnd()
查看代码用法示例 http://java-sl.com/tip_row_column.html
这篇关于尝试获取文本窗格中每行的起点和终点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!