[英]Create Custom Look and Feel for a JTabbedPane
I am trying to create a JTabbedPane that will always fill the top part of the Component with the tabs. 我正在尝试创建一个JTabbedPane,它将始终用选项卡填充Component的顶部。 Like so: 像这样:
And this is how it look now: 现在是这样的:
And the code for this part: 以及这部分的代码:
JTabbedPane tab = new JTabbedPane();
tab.addTab("Items", items);
tab.addTab("Categories", categories);
setContentPane(tab);
//Also tried to create a JTabbedPane class and see if i could remove the labels and manually add two buttons to the top but without success.
I want the tabs to use up as much space as possible without actually shrinking the content of the panels. 我希望选项卡在不实际缩小面板内容的情况下占用尽可能多的空间。 So could anyone tell me how to customize the JTabbedPane, the look and feed or just the tabs themselves in order to do that. 因此,谁能告诉我如何自定义JTabbedPane,外观和订阅源,或者只是自定义标签来实现此目的。
The easiest approach is probably to create your own component: 最简单的方法可能是创建自己的组件:
BorderLayout.PAGE_START
. 然后使用BorderLayout.PAGE_START
将此面板添加到“主”面板中。 Each of these button will display a specific panel when clicked. 单击每个按钮都会显示一个特定的面板。 CardLayout
. 创建另一个使用CardLayout
面板。 Add this panel to the "main" panel using BorderLayout.CENTER
. 使用BorderLayout.CENTER
将面板添加到“主”面板。 Each of these panels will represent a tab. 这些面板中的每一个都代表一个标签。 The other option is to look at the TabbedPaneUI
and find a method that paints each tab and modify the code for your requirement. 另一个选择是查看TabbedPaneUI
,找到一种绘制每个选项卡并修改代码的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.