JTabbedPane:更改选项卡标题时更改选项卡大小
我的 JFrame 中有一个 JTabbedPane myTab。它的第一个选项卡的标题为“旧标题”。我想动态更改标题,因此我使用此代码来设置:
myTab.setTitleAt(myTab.getSelectedIndex(), "my full new title");
不知何故,我的新标题比旧标题长。问题是,选项卡大小没有改变,并且它没有完全显示新标题,只有“我的完整n...”。
如果我单击该选项卡,该选项卡突然可以显示完整的新标题。
我也已经尝试过此代码来设置标题名称:
myTab.setTabComponentAt(myTab.getSelectedIndex(), new JLabel("my full new title"));
此代码可以帮助我根据新标题更改选项卡大小。但用于关闭选项卡的十字 (x) 不再存在。
有谁知道如何在更改选项卡标题时更改选项卡大小,但仍保留关闭选项卡选项?
谢谢并非常感谢!
I have a a JTabbedPane myTab within my JFrame. Its first tab has a title of "old title". I want to change the title dynamically, so I use this code to set:
myTab.setTitleAt(myTab.getSelectedIndex(), "my full new title");
And somehow my new title is longer than my old one. The problem is, the tab size does not change, and it does not display the new title fully, only "my full n...".
And if I click on the tab, suddenly the tab can show full new title.
I already tried this code too, to set the title name:
myTab.setTabComponentAt(myTab.getSelectedIndex(), new JLabel("my full new title"));
This code can help me change the tab size accordingly to the new title. But the cross (x) to close tab is not there anymore.
Does anyone know how to change the tab size when changing tab title, but still keep the close tab option?
Thank you and much appreciate!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未见过这种情况,
但这仅在一种情况下是可能的,您运行的代码不在 EDT 之外,
Swing 是单线程的,并且对 Swing GUI 的所有更改都必须在事件调度线程上完成,有关此主题的更多信息,请参见 Swing 中的并发,(我建议搜索这个常见主题在此论坛上),
来自代码,
I never saw that,
but this is possible only in one cases, code that you run is out of EDT,
Swing is single threaded and all changes to the Swing GUI must be done on Event Dispatch Thread, more about this topic in Concurency in Swing, (I'd suggest to search for this common topic on this Forum),
from code,