简体   繁体   English

JTextPane是否支持文本内存分页?

[英]Does JTextPane support text memory paging?

I'm trying to improve an existing implementation of document displaying component. 我正在尝试改进文档显示组件的现有实现。 One of the concerns expressed, that when loading a large bulk of text we will get an OOM exception. 表示关注的问题之一是,当加载大量文本时,我们将收到OOM异常。

From my previous experience with .net I do know that some base component implement paging, hence no all the text is visual loaded into the document hence things not only work faster but we will also, hopefully, avoid an OOM exception. 从我以前对.net的经验中,我确实知道某些基本组件实现了分页,因此不会将所有文本可视地加载到文档中,因此不仅可以更快地工作,而且希望避免OOM异常。

So I was wondering are there any base swing components, specifically JTextPanel, which support these capabilities? 所以我想知道是否有支持这些功能的基本摇摆组件,特别是JTextPanel?

Thank you for your help it is greatly appreciated 感谢您的帮助,不胜感激

It seems that Swing decouples the actual storage of the document from its presentation. Swing似乎将文档的实际存储与它的显示脱钩了。

I think you should be able to have the functionality you want by defining an AbstractDocument.Content implementation which takes care of the memory management (eg paging). 我认为您应该可以通过定义一个AbstractDocument.Content实现来拥有所需的功能,该实现负责内存管理(例如,分页)。

The DefaultStyledDocument takes an AbstractDocument.Content in its constructor, and the JTextPane takes a StyledDocument , so if you define that implementation you should be able to plug it in. DefaultStyledDocument在其构造函数中采用AbstractDocument.Content ,而JTextPane采用StyledDocument ,因此,如果您定义该实现,则应该可以将其插入。

I haven't tried this, so it's just a suggestion - you might be able to find implementations online. 我没有尝试过,所以这只是一个建议-您也许可以在线找到实现。

No, The JTextPane does not support memory pages. 不, JTextPane不支持内存页。 You can create a Docuemnt instance and read the file content into the Document without installing the Document in the JTextPane . 您可以创建一个Docuemnt实例并将文件内容读取到Document而无需在JTextPane安装Document Then get desired fragment of the Document and insert it into another one showing the desired fragment only. 然后获取所需的Document片段,然后将其插入另一个仅显示所需片段的片段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM