将 JTabbedPane 居中,但不将实际选项卡居中
我将如何根据该行选项卡中剩余的空间自动调整选项卡的长度大小。
图片:
如您所见,选项卡的宽度基于选项卡中的文本。
如果您需要我更好地解释我想要什么,那么就问我,因为我不知道我是否说得足够清楚。
How would I go about making the length of the tabs automatically resize based on how much room is left in that row of tabs.
Picture:
As you can see the tab's width is based off the text in the tab.
If you need me to explain what I want better then just ask me because I don't know if I made it clear enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用自定义组件并设置其首选大小。例如,在
TabComponentsDemo
:您必须根据布局的其他方面选择合适的尺寸,因此它不会是自动的。
JTabbedPane
的大小是它所添加到的Container
的尺寸和LayoutManager
的函数。在引用的示例中,框架内容窗格的默认布局是BorderLayout
,并且add(pane)
默认将其添加到中心。为了实现您的目标,我看到两种方法:
在现有选项卡中划分封闭
Container
的当前宽度并重新绘制选项卡式窗格,如示例。开发您自己的
TabbedPaneUI
并相应地解释SCROLL_TAB_LAYOUT
。You can use a custom component and set it's preferred size. For example, in
ButtonTabComponent
ofTabComponentsDemo
:You have to choose an appropriate dimension based on other aspects of your layout, so it won't be automatic.
The size of the
JTabbedPane
is a function of the dimensions andLayoutManager
of theContainer
to which it has been added. In the example cited, the default layout of the frame's content pane isBorderLayout
, andadd(pane)
adds it to the center by default.To accomplish your goal, I see two approaches:
Divide the current width of the enclosing
Container
among the existing tabs and repaint the tabbed pane, as shown in this example.Develop your own implementation of
TabbedPaneUI
and interpretSCROLL_TAB_LAYOUT
accordingly.