Swing/TabWithCloseButton のバックアップソース(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/TabWithCloseButton へ行く。
- 1 (2007-01-29 (月) 16:15:06)
- 2 (2007-01-29 (月) 20:54:34)
- 3 (2007-06-12 (火) 19:09:47)
- 4 (2007-07-26 (木) 17:11:08)
- 5 (2010-08-10 (火) 16:47:33)
- 6 (2010-12-09 (木) 02:18:25)
- 7 (2011-07-21 (木) 17:29:16)
- 8 (2013-02-10 (日) 00:03:02)
- 9 (2013-09-17 (火) 14:43:19)
- 10 (2013-10-10 (木) 11:45:07)
- 11 (2015-03-08 (日) 19:37:51)
- 12 (2016-05-23 (月) 01:05:07)
- 13 (2016-07-06 (水) 15:58:16)
- 14 (2017-04-04 (火) 14:17:08)
- 15 (2017-09-26 (火) 11:04:31)
- 16 (2019-04-03 (水) 19:29:53)
- 17 (2021-01-19 (火) 19:34:27)
- 18 (2023-10-06 (金) 15:35:46)
TITLE:JTabbedPaneにタブを閉じるボタンを追加 #navi(../) *JTabbedPaneにタブを閉じるボタンを追加 [#j2e3f8ab] >編集者:[[Terai Atsuhiro>terai]]~ 作成日:2007-01-29~ 更新日:&lastmod; #contents **概要 [#n84777ff] JDK 6 の新機能を使ってJTabbedPaneにタブを閉じるボタンを追加します。 #screenshot **サンプルコード [#ebac5cc8] class CloseButtonTabbedPane extends JTabbedPane { private final Icon icon; private final Dimension buttonSize; public CloseButtonTabbedPane(Icon icon) { super(); //icon = new CloseTabIcon(); this.icon = icon; buttonSize = new Dimension(icon.getIconWidth(), icon.getIconHeight()); } public void addTab(String title, final JComponent content) { JPanel tab = new JPanel(new BorderLayout()); tab.setOpaque(false); JLabel label = new JLabel(title); label.setBorder(BorderFactory.createEmptyBorder(0,0,0,4)); JButton button = new JButton(icon); button.setPreferredSize(buttonSize); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeTabAt(indexOfComponent(content)); } }); tab.add(label, BorderLayout.WEST); tab.add(button, BorderLayout.EAST); tab.setBorder(BorderFactory.createEmptyBorder(2,1,1,1)); super.addTab(null, content); setTabComponentAt(getTabCount()-1, tab); } } -&jnlp; -&jar; -&zip; **解説 [#h1ca2f51] JDK 6 から追加されたタブにコンポーネントを配置する機能を使って、JButtonをタブに追加しています。 [[他の以前のサンプル>Swing/TabWithCloseIcon]]と比べると、簡単に実装できて、コードも短くなっています。マウスがボタン上に来るとちゃんとロールオーバーするし、見栄えもそんなに悪くないと思います。 **参考リンク [#q5a6ecdb] -[[More Enhancements in Java SE 6 (Mustang)>http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/enhancements/?feed=JSC]] -[[JTabbedPaneにタブを閉じるアイコンを追加>Swing/TabWithCloseIcon]] **コメント [#q1163cb9] #comment