2016-07-27 159 views
1

问题:无法更改边缘周围标签面板或标签背景颜色的内容区域更改背景颜色标签面板

尝试:设置面板不透明,改变UIManager的默认设置,以及其他一些随机的东西。

enter image description here

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

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

+0

使用tabbedPane.setBackgroundAt()。有关更多详细信息,请参阅此。 http://stackoverflow.com/questions/8752037/how-to-change-background-color-of-jtabbedpane ...这可能会帮助你。 –

+0

如果你看源头,我已经尝试过,但我会看链接:) ty – DarkGuardsman

回答

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