Dynamically rebuild layout using Swing

I am building a Swing desktop application with similar functionality for Twitter. I have a feed page that displays tweets.

I have tweets in JPanel and you want to dynamically display new ones by adding new tweets at the top of JPanel and moving older ones. I tried to do this using MigLayout, using jpanel.add(tweet, "cell 0 0, wrap"), however this did not work as intended, and in order to display it with the layout I wanted, I had to call jpanel.revalidate().

This is not ideal, as many tweets may appear every second, and redrawing the panel can be quite slow. In any case, can I add new “tweets” to the top of the panel without redrawing?

+5
source share
2 answers

Although dynamic layouts are possible, as shown here and here , I would use a single-line layout, column JTablec TableModel, which reflects the effect of the pushdown stack that you want, possibly with an internal one Queue<Tweet>. JTablerendering is efficient and the component works well in JScrollPane.

+10
source

The short answer is no. Seriously, think about this issue. “I want to add new content but not refresh the screen”, as much as possible, as much as possible?

In the end, you have to do some painting. The question is how often.

However...

( ) "" , ( , , ).

- SwingWorker. publish process .

+10

All Articles