显示大量 JTextPanes?

发布于 2024-10-18 21:25:26 字数 365 浏览 7 评论 0原文

我在确定显示一堆 JTextPanes 的最佳设计实践时遇到了一些麻烦。假设我有 1000 个 JTextPane,每个 JTextPane 都包含一条风格化的消息,我想将它们一个一个地显示在另一个之上,就像在聊天中收到的消息一样。涉及 JTable 并将窗格放在其中会更好吗?或者只是将它们全部放在 JPanel/JScrollPane 中?我希望能够删除和添加 JTextPane,以及选择/聚焦特定的 JTextPane。我已经使用 JTable 创建了一个 alpha 原型(甚至不会考虑原型)解决方案并创建自定义模型/渲染,对于我想要实现的目标来说,它似乎过于复杂。

想知道仅编写一个自定义 JPanel 是否可以接受?另外,我对容纳多达 10,000 个 JPanel 的性能方面感兴趣?

I'm having a little trouble in determining the best design practices for displaying a bunch of JTextPanes. Let's say I have 1000 JTextPanes, each JTextPane contains a stylized message and I would like to display them one above the other, much like messages received in a chat. Would it be better to something involving a JTable and putting the panes inside there? or simply putting them all in a JPanel/JScrollPane? I would like to be able to remove and add JTextPanes, as well as select/focus a specific JTextPane. I've created a alpha-prototype(wouldn't even consider prototype) solution using JTable and creating custom models/renders, it just seems overly convoluted for what I'm trying to achieve.

Was wondering how acceptable it would be to just write a custom JPanel? Also I'm interested in the performance aspect of holding up to 10,000 JPanels?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

知足的幸福 2024-10-25 21:25:26

为什么不使用 1 个 JTextPane 和 10000 个不同的字符串,根据需要使用给定的字符串填充 JTextPane?

Why not have 1 JTextPane and 10000 different Strings, populating the JTextPane with the given String as needed?

瑕疵 2024-10-25 21:25:26

显示 10k 文本窗格对我来说毫无意义。您可能会耗尽资源。某些布局管理器甚至对可以添加的组件数量有限制。我认为流布局有 512 个限制,因此您需要嵌套面板才能实现您想要的效果,这会增加复杂性。

实际上显示 10K 的任何内容对我来说也没有多大意义。用户如何滚动并找到他们想要的内容?

但是,如果您确实需要类似的东西来允许您动态地添加/删除项目,那么我会考虑使用 JTable。它已经支持动态添加/删除。此外,您甚至可以使用 JTable 的过滤功能来提高您的应用程序的可用性。

我不确定你为什么说你需要自定义模型和渲染器。您可以在 JTable 中使用 HTML 来显示样式消息。

Displaying 10k text panes makes no sense to me. You would probably run out of resources. Some layout manager even have a limit on the number of components you can add. I think flow layout has a 512 limit so you would need to nest panels to achieve what you want which will add to the complexity.

Actually display 10K of anything doesn't make much sense to me either. How is the user ever going to scroll and find what they are looking for?

But if you do need something like this that allows you do tynamically add/remove items then I would look into a JTable. It already supports dynamic add/remove. Also you can even use the filtering features of JTable to make your application more usable.

I'm not sure why you say you need custom models and renderers. You can use HTML in a JTable for your styled messages.

林空鹿饮溪 2024-10-25 21:25:26

...风格化消息,我想将它们显示在另一个上方

在这种情况下,更好的方法是使用带有自定义单元格渲染器的 JList。

...stylized message and I would like to display them one above the other

The better way in this case is using JList with custom cell renderer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文