Java Reference
In-Depth Information
private void initPolygon() {
polygon = new Polygon();
int halfWidth = width/2;
int halfHeight = height/2;
polygon.addPoint (0, halfHeight);
polygon.addPoint (halfWidth, 0);
polygon.addPoint (width, halfHeight);
polygon.addPoint (halfWidth, height);
}
public int getIconHeight() {
return width;
}
public int getIconWidth() {
return height;
}
public void paintIcon(Component component, Graphics g, int x, int y) {
boolean selected = false;
g.setColor (color);
g.translate (x, y);
if (component instanceof AbstractButton) {
AbstractButton abstractButton = (AbstractButton)component;
selected = abstractButton.isSelected();
}
if (selected) {
g.fillPolygon (polygon);
} else {
g.drawPolygon (polygon);
}
g.translate (-x, -y);
}
}
Note If the DiamondAbstractButtonStateIcon icon were used with a component that isn't an
AbstractButton type, the icon would always be deselected, because the selection state is a property
of AbstractButton .
JRadioButtonMenuItem Class
The JRadioButtonMenuItem component has the longest name of all the Swing components. It
works like a JRadioButton , but resides on a menu. When placed with other JRadioButtonMenuItem
components within a ButtonGroup , only one component will be selected at a time. As with
the JRadioButton , the button model for the JRadioButtonMenuItem is the JToggleButton.
ToggleButtonModel .
 
Search WWH ::




Custom Search