gpt4 book ai didi

java - 保留 JTabbedPane 的指定颜色

转载 作者:行者123 更新时间:2023-12-02 01:05:33 24 4
gpt4 key购买 nike

我在 JTabeedPane 中有这个布局,背景如图所示。背景颜色没有更改为如图所示的颜色。我在设计时是如下结构。

JFrame (Background color: [0,115,153])
JPanel (Background color: [3,50,67])
JPanel (Background color: [16,110,173])
...
JPanel (Background color: [3,50,67])
JTabbedPane (Background color: [3,50,67])
Tab 1,2,3 (Background color: [3,50,67])

任何前景色或背景色均未启用白色,但它仍然可见。我在保持组件不透明并禁用不透明的情况下进行了测试,但没有效果。如何删除它?

enter image description here

最佳答案

恐怕这并不像人们想象的那么微不足道,因为这种格式完全由外观和感觉管理。
但是,您可以调用 tabbedPane.setUI(yourCustomUI); 来设置自定义 UI。

我准备了一个 UI 供您使用,希望它能节省您一些时间(请参阅内联注释进行自定义):

// your code...

tabbedPane.setUI(new MinimalisticTabbedPaneUI());

// your code...

public static class MinimalisticTabbedPaneUI extends BasicTabbedPaneUI {

// paints the border around the currently visible content
@Override
protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
// do nothing
}

// paints the border around each tab
@Override
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
// only paints a border if the tab is selected, edit this to add your personal formatting
if(isSelected){
super.paintTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
}
}
}

关于java - 保留 JTabbedPane 的指定颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60092852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com