Does JTextPane support text memory paging?

血红的双手。 提交于 2019-12-02 00:38:55

问题


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.

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.

So I was wondering are there any base swing components, specifically JTextPanel, which support these capabilities?

Thank you for your help it is greatly appreciated


回答1:


No, The JTextPane does not support memory pages. You can create a Docuemnt instance and read the file content into the Document without installing the Document in the JTextPane. Then get desired fragment of the Document and insert it into another one showing the desired fragment only.




回答2:


It seems that Swing decouples the actual storage of the document from its presentation.

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 (e.g. paging).

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.

I haven't tried this, so it's just a suggestion - you might be able to find implementations online.



来源:https://stackoverflow.com/questions/10399786/does-jtextpane-support-text-memory-paging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!