Google Tag Manager

2009/10/29

JCheckBoxMenuItem Icon

Code

UIManager.put("CheckBoxMenuItem.checkIcon", new Icon() {
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D)g;
    g2.translate(x,y);
    ButtonModel m = ((AbstractButton)c).getModel();
    g2.setPaint(m.isSelected()?Color.ORANGE:Color.GRAY);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
    g2.fillOval( 0, 2, 10, 10 );
    g2.translate(-x,-y);
  }
  public int getIconWidth()  { return 14; }
  public int getIconHeight() { return 14; }
});
menu.add(new JCheckBoxMenuItem("checkIcon test"));

References

No comments:

Post a Comment