1 | Icon createIcon(Color color) {↵ | | 1 | Icon createIcon(Color color) {
↵
|
2 | int width = 16;↵ | | 2 | int width = 16;
↵
|
3 | int height = 16;↵ | | 3 | int height = 16;
↵
|
4 | BufferedImage image = new BufferedImage(width, height,↵ | | 4 | BufferedImage image = new BufferedImage(width, height,
↵
|
5 | BufferedImage.TYPE_INT_ARGB);↵ | | 5 | BufferedImage.TYPE_INT_ARGB);↵
|
|
| | | 6 |
↵
|
6 | Graphics2D graphics = (Graphics2D) image.getGraphics();↵ | | 7 | Graphics2D graphics = (Graphics2D) image.getGraphics();
↵
|
7 | graphics.setColor(darker(color));↵ | | 8 | graphics.setColor(darker(color));
↵
|
8 | graphics.drawRect(1, 1, width - 3, height - 3);↵ | | 9 | graphics.drawRect(1, 1, width - 3, height - 3);
↵
|
9 | graphics.setColor(color);↵ | | 10 | graphics.setColor(color);
↵
|
10 | graphics.fillRect(2, 2, width - 4, height - 4);↵ | | 11 | graphics.fillRect(2, 2, width - 4, height - 4);
↵
|
11 | graphics.dispose();↵ | | 12 | graphics.dispose();↵
|
|
| | | 13 |
↵
|
12 | return new ImageIcon(image);↵ | | 14 | return new ImageIcon(image);
↵
|
13 | }↵ | | 15 | }↵
|
14 | ↵ | | |
|
| | | 16 |
↵
|
15 | private final static double FACTOR = 0.90;↵ | | 17 | private final static double FACTOR = 0.90;↵
|
|
| | | 18 |
↵
|
16 | private Color darker(Color c) {↵ | | 19 | private Color darker(Color c) {
↵
|
17 | return new Color(Math.max((int) (c.getRed() * FACTOR), 0), Math.max(↵ | | 20 | return new Color(Math.max((int) (c.getRed() * FACTOR), 0), Math.max(
↵
|
18 | (int) (c.getGreen() * FACTOR), 0), Math.max(↵ | | 21 | (int) (c.getGreen() * FACTOR), 0), Math.max(
↵
|
19 | (int) (c.getBlue() * FACTOR), 0));↵ | | 22 | (int) (c.getBlue() * FACTOR), 0));
↵
|
20 | | | 23 |
|