JTabbedPane - 在标签周围设置默认边框..? [英] JTabbedPane - set default border around tabs..?
问题描述
我在我的应用程序中使用了JTabbedPane。我添加了两个选项卡,它们是自定义类ContentPanel的实例。这扩展了JPanel并设置了背景,边框等等。基本上它意味着我不必设置我想要应用此颜色方案的每个JPanel的属性。我注意到它们的边框不仅出现了,而且还有另一个边框(我认为是蓝色 - 至少在我的屏幕上)出现在这个边框周围,连接到标签选择器本身(即你点击的按钮以获得适当的观点)。我想改变这个边界,因为它看起来很奇怪对金色/棕色配色方案。有谁知道如何做到这一点?我尝试过JTabbedPane.setBorder(边框b),但这不起作用。这只是围绕整个事物设置一个边框,包括选项卡选择器..不是我想要的。
I am using a JTabbedPane in my application. I have added two tabs which are instances of a custom class "ContentPanel". This extends JPanel and sets the background, border etc etc. Basically it means I dont have to set the properties of each JPanel I want to apply this colour scheme to. I notice that not only does their border appear but another border (which, I think, is blue - at least on my screen) appears around this border, connected to the tab "selectors" themselves (i.e. the buttons you click on to get the appropriate view). I would like to change this border as it just looks odd against a gold / brown colour scheme. Does anyone have any idea how to do this? I have tried JTabbedPane.setBorder(Border b) but that doesnt work. That simply sets a border around the entire thing, including the tab selectors.. not what I want.
任何帮助都将非常感谢。
Any help with this would be greatly appreciated.
推荐答案
这些颜色在外观中定义。如果你看一下 BasicTabbedPaneUI
的代码,你会发现 installDefaults()
设置了一堆 protected Color
实例变量。它们在L& F中定义的键也可在此处获得。
These colors are defined in the Look and Feel. If you look at the code for BasicTabbedPaneUI
, you will notice that installDefaults()
sets a bunch of protected Color
instance variables. The keys they are defined against in the L&F are also available here.
protected void installDefaults() {
LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background",
"TabbedPane.foreground", "TabbedPane.font");
highlight = UIManager.getColor("TabbedPane.light");
lightHighlight = UIManager.getColor("TabbedPane.highlight");
shadow = UIManager.getColor("TabbedPane.shadow");
darkShadow = UIManager.getColor("TabbedPane.darkShadow");
//...
// a lot more stuff
//...
}
如果您不想定义自己的L& F,您可以在选项卡式窗格上设置自定义UI委托:
If you do not want to go as far as define your own L&F, you have the ability to set a custom UI delegate on your tabbed pane:
myTabbedPane.setUI(new BasicTabbedPaneUI() {
@Override
protected void installDefaults() {
super.installDefaults();
highlight = Color.pink;
lightHighlight = Color.green;
shadow = Color.red;
darkShadow = Color.cyan;
focus = Color.yellow;
}
});
您当然可以更改这些颜色设置。如上所述,您将看到在哪里使用哪些变量。
you may of course want to change those color settings. As set, you will see which vars are used where.
这篇关于JTabbedPane - 在标签周围设置默认边框..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!