2016-07-27 163 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