[英]How to change tabs location in JTabbedPane?
I want to change tabs location from left to center. 我想将标签的位置从左更改为中心。 How can I do this?
我怎样才能做到这一点? I think I must change Look&Feel, but I don't know how.
我认为我必须更改外观,但我不知道如何。
From this: 由此:
To this: 对此:
As you already pointed out, you have to use an LookAndFeel which supports this design (centered Tab-Button). 正如您已经指出的,您必须使用支持这种设计的LookAndFeel(居中的Tab-Button)。
When your selected LaF does not support this, you have to write your own TabbedPaneUI. 如果您选择的LaF不支持此功能,则必须编写自己的TabbedPaneUI。
(But this may not be very easy.) (但这可能不是很容易。)
If you do not want to create your own TabbedPaneUI, you have to look for an existing custom TabbedPaneUI or TabbedPane-Component, which support this kind of layout. 如果您不想创建自己的TabbedPaneUI,则必须查找支持这种布局的现有自定义TabbedPaneUI或TabbedPane-Component。
You can take a look at this article, to get started: 您可以看一下这篇文章,开始:
http://www.javaworld.com/article/2072927/swing-gui-programmingloseandmaxtabbedpane--an-enha/swing-gui-programming/closeandmaxtabbedpane--an-enhanced-jtabbedpane.html http://www.javaworld.com/article/2072927/swing-gui-programmingloseandmaxtabbedpane--an-enha/swing-gui-programming/closeandmaxtabbedpane--an-enhanced-jtabbedpane.html
The placement of tabs is determined by the JTabbedPane
UI delegate, typically based on BasicTabbedPaneUI
. 选项卡的位置由
JTabbedPane
UI委托(通常基于BasicTabbedPaneUI
。 Not every Look & Feel implementation supports centered tabs, so there's no property that will work by default across platforms. 并非每个外观实现都支持居中的选项卡,因此默认情况下没有属性可在所有平台上使用。
As a concrete example, com.apple.laf.AquaLookAndFeel
supports centered tabs, as shown below. 作为一个具体示例,
com.apple.laf.AquaLookAndFeel
支持居中的选项卡,如下所示。 The class com.apple.laf.AquaTabbedPaneUI
, which implements the effect, is shown here . 此处显示了实现效果的
com.apple.laf.AquaTabbedPaneUI
类。
Because the implementation is non-trivial, a better choice is to support the user's Look & Feel choice using Preferences
. 因为实现是不平凡的,所以更好的选择是使用
Preferences
来支持用户的外观选择。 A suitable Look & Feel selection control is shown here and here . 此处和此处显示了合适的外观选择控件。
The source for the example above is seen here . 上面示例的来源在这里可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.