更改选项卡式面板的背景颜色

时间:2016-07-27 00:47:54

标签: java swing colors background tabs

问题:无法更改选项卡式面板或标签背景颜色的内容区域边缘

尝试:设置面板不透明,更改UIManager默认值以及其他一些随机内容。

enter image description here

代码:https://gist.github.com/DarkGuardsman/b86c542cc168d1c792a01a4d44dba229

注意:我没有编写所有这些代码,因为我正在更新具有界面更改的现有项目。所以请注意解决方案而不是编码风格。

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,但我确信它不是最好的解决方案。在发布之前我最初是为了这个。阅读完UI代码后,我发现它在内容面板周围绘制了边框。覆盖执行大部分边框的paintTabBackground方法解决了这个问题。

private class TabUI extends BasicTabbedPaneUI
{
    @Override
    protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected ) {
        g.setColor(LauncherFrame.secondaryColor);
        switch(tabPlacement) {
            case LEFT:
                g.fillRect(x+1, y+1, w-1, h-3);
                break;
            case RIGHT:
                g.fillRect(x, y+1, w-2, h-3);
                break;
            case BOTTOM:
                g.fillRect(x+1, y, w-3, h-1);
                break;
            case TOP:
            default:
                g.fillRect(x+1, y+1, w-3, h-1);
        }
    }
}

enter image description here

相关问题