0

试图在文本窗格中获取每行的起点和终点:文本窗格包含(注意目标是每行的结尾,不包括空白行):

(blank space line) 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

4

1 回答 1

1

你混合模型和视图。Document只是模型,但行数取决于视图(内容的宽度)。

利用javax.swing.text.Utilities.getRowStart()/getRowEnd()

查看代码使用示例http://java-sl.com/tip_row_column.html

于 2012-12-26T16:27:42.263 回答