Swing/TabMnemonic のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/TabMnemonic へ行く。
- 1 (2013-01-17 (木) 15:08:35)
- 2 (2013-05-19 (日) 16:38:44)
- 3 (2013-07-26 (金) 01:33:11)
- 4 (2015-10-20 (火) 17:22:08)
- 5 (2017-04-13 (木) 12:16:00)
- 6 (2018-01-23 (火) 13:22:01)
- 7 (2018-01-25 (木) 18:16:54)
- 8 (2018-06-21 (木) 17:41:48)
- 9 (2019-02-12 (火) 15:29:26)
- 10 (2020-12-03 (木) 10:16:22)
- 11 (2022-08-26 (金) 12:32:48)
- 12 (2022-08-27 (土) 23:46:36)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JTabbedPaneのタブにMnemonicを追加 #navi(../) #tags() RIGHT:Posted by &author(aterai); at 2008-09-01 *JTabbedPaneのタブにMnemonicを追加 [#v5ca5302] JTabbedPaneのタブにMnemonicを追加します。 -&jnlp; -&jar; -&zip; //#screenshot #ref(http://lh3.ggpht.com/_9Z4BYR88imo/TQTUu2fjTpI/AAAAAAAAAmg/EST6gnFRH84/s800/TabMnemonic.png) **サンプルコード [#o82d41ae] #code(link){{ tab.addTab("Button", new JButton("button")); tab.setMnemonicAt(3, KeyEvent.VK_B); tab.setDisplayedMnemonicIndexAt(3, 0); }} **解説 [#h7d38d0a] 上記のサンプルコードは、三番目のタブにAlt+Bでフォーカスが移動するように、JTabbedPane#setMnemonicAt メソッドを使用しています。 また、タブタイトルの先頭文字(B)にアンダーラインが入るようにJTabbedPane#setDisplayedMnemonicIndexAt メソッドで設定しています。 ---- JDK 6 以降でタブにJComponentを追加する場合、JTabbedPane#setDisplayedMnemonicIndexAt メソッドではMnemonicにアンダーラインは引かれないので、追加したコンポーネント自体にアンダーラインを引くよう設定します。 #code{{ int index = tab.getTabCount(); String tabTitle = "label(0)"; JPanel p = new JPanel(new BorderLayout()); JLabel label = new JLabel(tabTitle); JButton button = new JButton("x"); p.add(label, BorderLayout.WEST); p.add(button, BorderLayout.EAST); tab.addTab(tabTitle, new JTree()); tab.setTabComponentAt(index, p); tab.setMnemonicAt(index, KeyEvent.VK_0); label.setDisplayedMnemonic(KeyEvent.VK_0); }} //**参考リンク **コメント [#kb7f7635] #comment