Swing/ToolButtonPopup のバックアップ差分(No.5)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/ToolButtonPopup へ行く。
- 1 (2006-07-10 (月) 10:10:27)
- 2 (2006-07-10 (月) 16:09:23)
- 3 (2006-07-10 (月) 23:39:24)
- 4 (2006-12-06 (水) 16:43:05)
- 5 (2007-01-29 (月) 20:44:59)
- 6 (2007-09-12 (水) 12:53:00)
- 7 (2008-12-15 (月) 16:14:44)
- 8 (2011-04-04 (月) 14:23:21)
- 9 (2011-04-04 (月) 17:15:55)
- 10 (2011-04-04 (月) 20:27:46)
- 11 (2011-05-05 (木) 08:26:05)
- 12 (2011-06-05 (日) 02:41:25)
- 13 (2013-02-27 (水) 13:54:28)
- 14 (2013-02-27 (水) 17:52:19)
- 15 (2013-08-21 (水) 20:52:55)
- 16 (2013-09-07 (土) 00:31:22)
- 17 (2014-11-22 (土) 03:59:58)
- 18 (2014-11-25 (火) 03:03:31)
- 19 (2014-11-29 (土) 01:44:44)
- 20 (2015-02-13 (金) 23:01:26)
- 21 (2015-02-26 (木) 14:04:33)
- 22 (2015-03-19 (木) 16:36:24)
- 23 (2016-02-03 (水) 18:23:54)
- 24 (2016-05-27 (金) 13:18:53)
- 25 (2017-08-17 (木) 14:22:16)
- 26 (2018-02-24 (土) 19:51:30)
- 27 (2018-08-12 (日) 18:47:04)
- 28 (2018-10-30 (火) 16:34:23)
- 29 (2019-05-22 (水) 19:34:28)
- 30 (2020-10-29 (木) 17:59:23)
- 31 (2022-08-19 (金) 12:21:23)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JToggleButtonからポップアップメニューを開く
#navi(../)
*JToggleButtonからポップアップメニューを開く [#e15ce510]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2006-07-10~
更新日:&lastmod;
#contents
**概要 [#sd52e2d8]
クリックするとポップアップメニューを表示するJToggleButtonを作成し、これをツールバーに追加します。
#screenshot
**サンプルコード [#o01c8911]
class MenuToggleButton extends JToggleButton {
private final Icon i = new MenuArrowIcon();
private final String space;
public MenuToggleButton(final AbstractAction aa, String space) {
super(new AbstractAction((String)aa.getValue("Name")+space) {
public void actionPerformed(ActionEvent ae) {
aa.actionPerformed(ae);
}
});
this.space = space;
this.setFocusPainted(false);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Dimension dim = getSize();
Insets ins = getInsets();
int h = dim.height;
int w = SwingUtilities.computeStringWidth(g.getFontMetrics(), space);
int x = dim.width-ins.right-i.getIconWidth()-(w-i.getIconWidth())/2;
int y = ins.top+(dim.height-ins.top-ins.bottom-i.getIconHeight())/2;
i.paintIcon(this, g, x, y);
}
}
-&jnlp;
-&jar;
-&zip;
**解説 [#i6f6caf9]
上記のサンプルでは、ボタンの文字列に空白文字を追加することで右側にスペースを取得し、ここに下向きの矢印を上書きしています。
**参考リンク [#f95e2567]
-[[XP Style Icons - Windows Application Icon, Software XP Icons>http://www.icongalore.com/]]
--アイコンを利用しています。
-[[Swing bug? cannot set width of JToggleButton>http://forum.java.sun.com/thread.jspa?threadID=791450]]
**コメント [#h4a49a4d]
#comment