玻璃面板控制台式文本显示组件
我正在尝试为缓慢的操作提供进度报告,以从屏幕底部向上滚动的文本形式提供有关正在发生的事情的详细信息 - 这是您可能在视频游戏中看到过几次的效果。重新加载地图、建立网络连接等。
玻璃窗格似乎是获得文本覆盖的方法,我已经做了这么多。我的问题正是使用什么组件来显示实际的文本。
JTextArea 可以显示文本,但据我所知,它只能从屏幕顶部向下显示 - 有没有办法让它从屏幕底部向上滚动文本?
相比之下,JLabel 可以将第一行文本与屏幕底部对齐,甚至可以在该行上附加文本,但是当我添加更多由换行符分隔的行时,即使在调用 repaint 和 validate 之后,它似乎也会吞掉它们。有没有办法让它随着新文本向上滚动?
或者我应该使用另一个组件来代替?
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 the new text?
Or is there another component I should be using instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的很喜欢 JXLayer 在 Swing 组件上分层的效果。 JXLayer 一度计划包含在 Java 7。不幸的是,Java.net 上的迁移丢失了作者拥有的所有好内容。还有一些其他很棒的资源(此资源需要 Java 7)< /a> 在网络上。我使用 JXLayer 为面板提供忙碌状态,具有类似网络的旋转器和灰色外观。
另一种替代方案(恕我直言,功能不如 JXLayer)是 MigLayout 具有绝对定位,这可能比 GlassPane 更容易。
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
是最简单的。否则,您将必须覆盖paintComponent
才能执行任何奇特的操作,例如为文本移动设置动画。JLabel
would be the easiest. Otherwise you will have to overridepaintComponent
to do anything fancy like animating the text movement.