RFR: 8357305: Compilation failure in javax/swing/JMenuItem/bug6197830.java [v2]
Alexey Ivanov
aivanov at openjdk.org
Tue May 20 18:11:00 UTC 2025
On Tue, 20 May 2025 16:33:38 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> Manukumar V S has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Review comments fixed : Rearranged and reused code by creating a new Helper MenuItemTestHelper.java
>
> test/jdk/javax/swing/JMenuItem/MenuItemTest/MenuItemTestHelper.java line 74:
>
>> 72: g.fillRect(x, y, 15, 10);
>> 73: g.setColor(color);
>> 74: }
>
> Perhaps, both `Icon` instances could even be refactored into its own class that accepts color, width and height.
>
> However, this is close to over-engineering the test code…
Anyway, it makes the code cleaner:
private static final class ColoredIcon implements Icon {
private final Color color;
private final int width;
private final int height;
private ColoredIcon(Color color, int width, int height) {
this.color = color;
this.width = width;
this.height = height;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Color oldColor = g.getColor();
g.setColor(color);
g.fillRect(x, y, width, height);
g.setColor(oldColor);
}
@Override
public int getIconWidth() {
return width;
}
@Override
public int getIconHeight() {
return height;
}
}
It may be a record, yet using a class will make backporting to previous versions easier.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25319#discussion_r2098585654
More information about the client-libs-dev
mailing list