Swing/TabWidth のバックアップソース(No.11)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/TabWidth へ行く。
- 1 (2005-06-13 (月) 03:13:10)
- 2 (2005-06-13 (月) 05:41:29)
- 3 (2005-07-09 (土) 17:22:59)
- 4 (2005-10-04 (火) 14:54:07)
- 5 (2006-01-06 (金) 14:48:06)
- 6 (2006-02-27 (月) 16:48:13)
- 7 (2006-12-22 (金) 18:56:11)
- 8 (2007-08-30 (木) 14:46:14)
- 9 (2012-08-08 (水) 18:46:10)
- 10 (2013-03-28 (木) 18:01:45)
- 11 (2014-10-26 (日) 15:41:07)
- 12 (2015-11-15 (日) 19:32:18)
- 13 (2017-05-02 (火) 18:32:51)
- 14 (2018-03-01 (木) 14:58:22)
- 15 (2019-08-23 (金) 16:07:47)
- 16 (2021-04-17 (土) 02:58:20)
--- title: JTabbedPaneのタブ幅を固定 tags: [JTabbedPane] author: aterai pubdate: 2005-06-13T03:13:10+09:00 description: JTabbedPaneのタブ幅をできるだけ一定のサイズに固定します。 --- * 概要 [#ke4395dc] `JTabbedPane`のタブ幅をできるだけ一定のサイズに固定します。 #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTVAYay_fI/AAAAAAAAAm8/1gWXosPj93A/s800/TabWidth.png) * サンプルコード [#gf9ffe1b] #code(link){{ tab1.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI() { @Override protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { int i = super.calculateTabWidth(tabPlacement, tabIndex, metrics); return i<100 ? 100 : i; } }); }} * 解説 [#vdaead36] 上記のサンプルでは、`BasicTabbedPaneUI`の`calculateTabWidth`メソッドをオーバーライドして、下の`JTabbedPane`のタブ幅がタイトル文字列の長さにかかわらず一定になるように指定しています。 `JTabbedPane`のサイズが十分で無い場合、タブ列が二段になってタブは指定された幅を維持出来なくなります。 ---- 以下のように、`html`タグを使ってタブ幅を固定する方法もあります。 #code{{ public String makeTitle(String title) { return "<html><table width='100'><tr><td align='center'>"+ title+ "</td></tr></table>"; } }} //* 参考リンク * コメント [#t721888e] #comment #comment