在 JTextArea 中显示大文件
我目前正在从事 Swing UI 分配工作。这项工作涉及在 JTextArea 中显示大文件内容。文件大小可达 2 GB。
我最初的想法是从文件中延迟加载内容,比如说将向用户显示 1 MB 的内容。当用户滚动时,我将检索要显示的下一个 1 MB 内容。所有这些操作都将在后台线程(Swing Worker)中发生。
我查看了 JTextArea API,方法 insert 采用 String 和 int(插入位置)作为参数。
这已经足够了,但我担心性能,因为检索到的内容(一次 1 MB)必须转换为 String 对象。
是否有任何其他解决方法或任何其他替代/更好的解决方案。
I'm currently working in Swing UI Assignment. This work involves showing large file content in JTextArea. The file size can be as large as 2 GB.
My initial idea is to lazily load content from the file, say 1 MB of content will be shown to the user. As the user scrolls i will retrieve the next 1 MB of content to be shown. All these operation will be happening in background thread (Swing Worker).
I looked at the JTextArea API, the method insert takes String and int(position of the insert) as the parameter.
This will suffice, but i'm worried about performance, because the content (1 MB at a time) retrieved will have to be converted to String object.
Is there any other work around or any other alternative/better solution for this.
效率问题在于文档模型。
可行的方法可能是提供有效的自定义
文档
实施。然而,就我个人而言,我会尝试重新考虑并尝试拥有不同的用户界面。谁愿意滚动浏览 2 GB 的数据?
The efficiency issue would lie in the Document model.
The way to go is probably to provide an efficient custom
Document
implementation.However, personally, I would try to reconsider and try to have a different user interface. Who would want to scroll through 2 GB of data anyway?