使用Swing动态重新排列布局

编程入门 行业动态 更新时间:2024-10-23 04:59:57
本文介绍了使用Swing动态重新排列布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用具有与Twitter类似功能的Swing构建桌面应用程序。我有一个提要页面,其中显示推文。

I am building a desktop app with Swing with similar functionality to Twitter. I have a "feed" page where "tweets" are displayed.

我在JPanel中有推文,并希望通过放置新动态来动态显示新推文JPanel顶部的推文,并将旧的推文降低。我试图通过使用 jpanel.add(tweet,cell 0 0,wrap)来使用MigLayout执行此操作但是这不能按预期工作并且为了获得它显示我想要的布局我必须调用 jpanel.revalidate()。

I have the "tweets" in a JPanel and want to dynamically display new ones coming in by placing new "tweets" at the top of the JPanel and moving older ones down. I was trying to do this with MigLayout by using jpanel.add(tweet, "cell 0 0, wrap") however this didn't work as intended and in order to get it to display with the layout I wanted I had to call jpanel.revalidate().

这不是理想的因为每秒都会有很多推文进入,重新绘制面板可能会很慢。无论如何我可以在面板顶部添加新的推文而无需重新绘制?

This is not ideal as there could be many tweets coming in every second and redrawing the panel can be quite slow. Is there anyway I can add new "tweets" to the top of the panel without redrawing?

推荐答案

虽然可以进行动态布局,如此处和此处,我使用单列 JTable ,其中 TableModel 反映了您想要的下推式堆栈效果,可能是内部队列< Tweet> 。 JTable 渲染效率很高,组件在 JScrollPane 中运行良好。

Although dynamic layouts are possible, as shown here and here, I'd use a one-column JTable with a TableModel that reflects the pushdown stack effect you want, perhaps one having an internal Queue<Tweet>. JTable rendering is efficient, and the component works well in a JScrollPane.

更多推荐

使用Swing动态重新排列布局

本文发布于:2023-11-11 18:08:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:排列   布局   动态   Swing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!