拉伸 JLabel 文本
有没有办法让 JLabel 的文本拉伸到 100% 高度?当组件的大小发生变化时,我也需要更新文本。
我看到了一些可行的解决方案;它涉及计算和设置字体大小,使其显示正确的高度。我还必须在高度发生变化时添加监听器以使其做出响应,但我不知道应该在哪里执行此操作。
我希望布局管理器有更好的解决方案,但找不到任何东西。
有什么想法吗?
Is there a way to make a JLabel's text stretch to 100% height? I need the text to update when the component's size changes as well.
I saw some solution that could work; It involved calculating and setting the font size so it appears the right height. I would have also have to add listeners for when the height changed to make it respond and I do not know exactly where I should do that.
I am hoping for a better solution with layout managers, but couldn't find anything.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在下面所示的方法中,使用
TextLayout
使用适当大的Font
大小并缩放以填充组件。 此处有一个相关示例。In the approach shown below, the desired text is imaged using
TextLayout
using a suitably largeFont
size and scaled to fill the component. There's a related example here.