Swing/TabTitleHighlight のバックアップ差分(No.6)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/TabTitleHighlight へ行く。
- 1 (2007-12-10 (月) 16:19:56)
- 2 (2007-12-10 (月) 20:58:44)
- 3 (2008-01-16 (水) 19:08:13)
- 4 (2013-01-27 (日) 19:49:18)
- 5 (2014-11-08 (土) 01:41:12)
- 6 (2015-12-10 (木) 04:04:12)
- 7 (2017-05-31 (水) 20:16:25)
- 8 (2018-05-17 (木) 16:32:51)
- 9 (2020-05-14 (木) 16:18:10)
- 10 (2021-11-05 (金) 00:00:53)
- 11 (2025-01-03 (金) 08:57:02)
- 12 (2025-01-03 (金) 09:01:23)
- 13 (2025-01-03 (金) 09:02:38)
- 14 (2025-01-03 (金) 09:03:21)
- 15 (2025-01-03 (金) 09:04:02)
- 16 (2025-06-19 (木) 12:41:37)
- 17 (2025-06-19 (木) 12:43:47)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- title: JTabbedPaneのタブ文字列をハイライト tags: [JTabbedPane, MouseMotionListener] author: aterai pubdate: 2007-12-10T16:19:56+09:00 description: JTabbedPaneのタブ上に、マウスカーソルがある場合、その文字色を変更します。 --- * 概要 [#u3553382] `JTabbedPane`のタブ上に、マウスカーソルがある場合、その文字色を変更します。 #download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTU7QqLieI/AAAAAAAAAm0/dgW3rio-pzA/s800/TabTitleHighlight.png) * サンプルコード [#r7ba520e] #code(link){{ jtp.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { JTabbedPane source = (JTabbedPane)e.getSource(); JTabbedPane source = (JTabbedPane) e.getSource(); int tgt = source.indexAtLocation(e.getX(), e.getY()); for(int i=0;i<source.getTabCount();i++) { source.setForegroundAt(i, i==tgt ? Color.GREEN : Color.BLACK); for (int i = 0; i < source.getTabCount(); i++) { source.setForegroundAt(i, i == tgt ? Color.GREEN : Color.BLACK); } } }); }} * 解説 [#a0f82c36] 上記のサンプルでは、`JTabbedPane`に`MouseMotionListener`を追加し、`JTabbedPane#indexAtLocation`メソッドで、マウスカーソルの下にあるタブを取得しています。 `GTKLookAndFeel`(`Ubuntu`+`GNOME`+`jdk1.6.0_03`)などでは、タブの文字色を変更出来ないようです。 * 参考リンク [#c27d90d2] - [http://terai.xrea.jp/Swing/ColorTab.html JTabbedPaneの選択文字色を変更] - [[JTabbedPaneの選択文字色を変更>Swing/ColorTab]] * コメント [#y35f5c6d] #comment #comment