• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JTabbedPaneで選択したタブの高さを変更
#navi(../)
RIGHT:Posted by [[terai]] at 2010-04-05
#tags()
RIGHT:Posted by &author(aterai); at 2010-04-05
*JTabbedPaneで選択したタブの高さを変更 [#dd299fb8]
JTabbedPaneで選択したタブの高さを変更します。

-&jnlp;
-&jar;
-&zip;

#screenshot
//#screenshot
#ref(http://lh5.ggpht.com/_9Z4BYR88imo/TQTS0RHzbTI/AAAAAAAAAjY/__rqkPO3bsk/s800/SelectedTabHeight.png)

**サンプルコード [#qcce822e]
#code{{
#code(link){{
tabbedPane.setUI(new com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI() {
  @Override protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
    return 32;
  }
  @Override protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects,
                                    int tabIndex, Rectangle iconRect, Rectangle textRect) {
    Rectangle tabRect  = rects[tabIndex];
    int selectedIndex  = tabPane.getSelectedIndex();
    boolean isSelected = selectedIndex == tabIndex;
    if(!isSelected) {
      //JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT
      rects[tabIndex].y = 16;
      rects[tabIndex].height = 16;
    }
    super.paintTab(g,tabPlacement,rects,tabIndex,iconRect,textRect);
  }
});
}}

**解説 [#ebec32af]
上記のサンプルでは、選択されていないタブの高さを低くすることで、選択されたタブの高さが目立つように設定しています。

- 対応しているのは、JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT の場合のみ

//**参考リンク
**コメント [#b624a66d]
#comment