Google Tag Manager

2010/04/05

JTabbedPane selected tab height

Code

class WindowsTabHeightTabbedPaneUI extends WindowsTabbedPaneUI {
  private static final int TAB_AREA_HEIGHT = 32;
  @Override protected int calculateTabHeight(
      int tabPlacement, int tabIndex, int fontHeight) {
    return TAB_AREA_HEIGHT;
  }
  @Override protected void paintTab(
      Graphics g, int tabPlacement, Rectangle[] rects,
      int tabIndex, Rectangle iconRect, Rectangle textRect) {
    if (tabPane.getSelectedIndex() != tabIndex
        && tabPlacement != JTabbedPane.LEFT
        && tabPlacement != JTabbedPane.RIGHT) {
      int tabHeight = TAB_AREA_HEIGHT / 2 + 3;
      rects[tabIndex].height = tabHeight;
      if (tabPlacement == JTabbedPane.TOP) {
        rects[tabIndex].y = TAB_AREA_HEIGHT - tabHeight + 3;
      }
    }
    super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
  }
}

References