开发者

Component for glass pane console-style text display

开发者 https://www.devze.com 2023-03-14 06:27 出处:网络
I\'m trying to provide a progress report for a slow operation, in the form of text scrolling up from the bottom of the screen with details on what\'s going on - it\'s an effect you may have seen a few

I'm trying to provide a progress report for a slow operation, in the form of text scrolling up from the bottom of the screen with details on what's going on - it's an effect you may have seen a few times in video games when they're loading maps, making network connections and suchlike.

Glass pane seems to be the way to get the text overlay, that much I have working. My problem is exactly what component to use for the actual text display.

JTextArea can display text, but as far as I can see, it can only do it from the top of the screen down - is there a way to make it scroll text up from the bottom of the screen?

JLabel by contrast can align the first line of text to the bottom of the screen, and even take appended text on that line, but when I add more lines separated by newline characters, it just seems to swallow them up even after calling repaint and validate. Is there a way to make it scroll up with开发者_C百科 the new text?

Or is there another component I should be using instead?


I really like JXLayer for effects layered over Swing components. JXLayer was at one point scheduled to be included in Java 7. Unfortunately the moving around that has been going on Java.net lost all the good content that the author had. There are still some other great resources around (Java 7 required for this one) on the web. I use JXLayer to provide panels with a busy state having a web-like spinner and greyed out appearance.

Another alternative (not as capable as JXLayer IMHO) is MigLayout has absolute positioning, which is maybe easier than the GlassPane.


JLabel would be the easiest. Otherwise you will have to override paintComponent to do anything fancy like animating the text movement.

0

精彩评论

暂无评论...
验证码 换一张
取 消