尝试获取文本窗格中每行的起点和终点: 文本窗格包含(注意目标是每行的末尾,不包括空格行):
(空白行) MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDKVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtarget MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtarget MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDDFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKDDDDDDDEEQNKEALQDVEDENQtarget
//这就是我所拥有的
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);
}
这是我得到的(第一和第二个元素),然后挂起: 0 1 1 232
答案 0 :(得分:1)
您混合模型和视图。 Document
只是模型,但行数取决于视图(内容的宽度)。
使用javax.swing.text.Utilities.getRowStart()/getRowEnd()