在JEditorPane中获取可见文本

在JEditorPane中获取可见文本,第1张

在JEditorPane中获取可见文本

您可以使用视口来获取视图的位置和大小。

JViewport viewport = scrollPane.getViewport();Point startPoint = viewport.getViewPosition();Dimension size = viewport.getExtentSize();Point endPoint = new Point(startPoint.x + size.width, startPoint.y + size.height);

一旦知道了视口的起点/终点,就可以使用:

int start = editorPane.viewToModel( startPoint );int end = editorPane.viewToModel( endPoint );

一旦知道了文本的偏移量,就可以从组件中获取文本:

String text = editorPane.getText(start, end - start);

没有代码经过测试。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5501898.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存