逐行阅读JTextPane [英] Read JTextPane line by line

查看:88
本文介绍了逐行阅读JTextPane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以逐行读取JTextPane的内容?就像BufferedReader一样?

Is there a way to read the contents of a JTextPane line by line? Much like the BufferedReader?

推荐答案

Element root = textPane.getDocument().getDefaultRootElement();

一旦获得根元素,就可以检查以查看存在多少个子元素(即行).然后,您可以获得每个子元素,并使用开始/结束偏移量方法来获取该特定行的文本.

Once you get the root Element you can check to see how many child elements (ie. lines) exist. Then you can get each child Element and use the start/end offset methods to get the text for that particular line.

这比将所有文本打包成一个大字符串然后再次将其分割更有效.

This would be more efficient than getting all the text in one big string and then splitting it again.

这篇关于逐行阅读JTextPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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