Swing/RadioButtonMenuItemIcon のバックアップ(No.3)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/RadioButtonMenuItemIcon へ行く。
- 1 (2012-08-08 (水) 19:51:09)
- 2 (2012-12-25 (火) 05:11:35)
- 3 (2014-11-22 (土) 03:59:58)
- 4 (2014-12-11 (木) 15:07:29)
- 5 (2016-02-28 (日) 23:39:40)
- 6 (2017-07-13 (木) 13:26:15)
- 7 (2018-07-14 (土) 18:54:22)
- 8 (2020-07-15 (水) 16:12:41)
- 9 (2021-12-14 (火) 18:54:56)
- 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: JRadioButtonMenuItemのチェックアイコンを変更する tags: [JRadioButtonMenuItem, Icon, UIManager] author: aterai pubdate: 2010-11-08T16:26:30+09:00 description: JRadioButtonMenuItemのチェックアイコンを変更します。
概要
JRadioButtonMenuItem
のチェックアイコンを変更します。
Screenshot

Advertisement
サンプルコード
//com.sun.java.swing.plaf.windows.WindowsIconFactory.java
class RadioButtonMenuItemIcon1 implements Icon, UIResource, Serializable {
@Override public void paintIcon(Component c, Graphics g, int x, int y) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
if(b.isSelected()) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.fillRoundRect(x+3,y+3, getIconWidth()-6, getIconHeight()-6, 4, 4);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
}
@Override public int getIconWidth() { return 12; }
@Override public int getIconHeight() { return 12; }
}
class RadioButtonMenuItemIcon2 implements Icon, UIResource, Serializable {
@Override public void paintIcon(Component c, Graphics g, int x, int y) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
if(b.isSelected()) {
//g.fillRoundRect(x+3,y+3, getIconWidth()-6, getIconHeight()-6, 4, 4);
g.fillOval(x+2,y+2, getIconWidth()-5, getIconHeight()-5);
//g.fillArc(x+2,y+2,getIconWidth()-5, getIconHeight()-5, 0, 360);
}
}
@Override public int getIconWidth() { return 12; }
@Override public int getIconHeight() { return 12; }
}
View in GitHub: Java, Kotlin解説
上記のサンプルでは、WindowsLookAndFeel
(Java1.6.0
)で、JRadioButtonMenuItem
のチェックアイコンがすこし歪?なので以下のように修正しています。
default
- デフォルト
ANTIALIASING
com.sun.java.swing.plaf.windows.WindowsIconFactory
のアイコンをg2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
でアンチエイリアス
fillOval
fillRoundRect
ではなく、fillOval
を使用