1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JButton button = new JButton(new Icon() {
public int getIconHeight()
{
return 16;
}
public int getIconWidth()
{
return 16;
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
Color initialColor = g.getColor();
g.setColor(Color.RED);
g.drawLine(x + 1, y + 1, x + 15, y + 15);
g.setColor(initialColor);
}
});
frame.getContentPane().add(button);
frame.pack();
frame.setVisible(true);
} |
Partager