Swing/HoverCloseButton のバックアップ(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/HoverCloseButton へ行く。
- 1 (2008-01-21 (月) 15:27:41)
- 2 (2008-03-19 (水) 21:07:27)
- 3 (2014-10-02 (木) 03:46:09)
- 4 (2015-01-21 (水) 18:32:52)
- 5 (2016-04-27 (水) 17:46:19)
- 6 (2017-07-28 (金) 18:24:09)
- 7 (2018-07-31 (火) 13:58:59)
- 8 (2020-08-04 (火) 20:56:30)
- 9 (2021-12-23 (木) 17:18:41)
- 10 (2025-01-03 (金) 08:57:02)
- 11 (2025-01-03 (金) 09:01:23)
- 12 (2025-01-03 (金) 09:02:38)
- 13 (2025-01-03 (金) 09:03:21)
- 14 (2025-01-03 (金) 09:04:02)
TITLE:JTabbedPaneのCloseButtonをフォーカスがある場合だけ表示
JTabbedPaneのCloseButtonをフォーカスがある場合だけ表示
編集者:Terai Atsuhiro
作成日:2008-01-21
更新日:2021-12-23 (木) 17:18:41
概要
JTabbedPaneのタブを閉じるボタンを、タブにフォーカスがある場合だけ表示します。
#screenshot
サンプルコード
public MyJTabbedPane() {
super();
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
addMouseMotionListener(new MouseMotionAdapter() {
private int prev = -1;
@Override public void mouseMoved(MouseEvent e) {
JTabbedPane source = (JTabbedPane)e.getSource();
int focussed = source.indexAtLocation(e.getX(), e.getY());
int selected = source.getSelectedIndex();
if(focussed==prev) return;
for(int i=0;i<source.getTabCount();i++) {
TabPanel tab = (TabPanel)source.getTabComponentAt(i);
tab.setButtonVisible(i==selected || i==focussed);
}
prev = focussed;
}
});
}
- &jnlp;
- &jar;
- &zip;
解説
上記のサンプルでは、JDK 6 で導入されたタブにコンポーネントを追加する機能を使って、タブ上にマウスカーソルがある場合や、フォーカスがある場合にだけJButtonを表示しています。