On Tue, 12 Aug 2025 11:34:41 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> wrote:
>> I understand that methods in SwingUtilities3 had to be static, but why the >> colors couldn't be passed to the method as parameters? [I did >> suggest](https://github.com/openjdk/jdk/pull/23324#discussion_r2169199694) >> passing the colors as parameters: >> >>> Pass the colors explicitly as parameters to the >>> `SwingUtilities3.paintAccText` method. >> >> Storing the colors as global variables in a utility class leaks these >> objects. After L&F is changed to something else, these colors persist in >> `SwingUtilities3`. >> >> The same applies to the new static fields in `WindowsMenuItemUI`. They're >> not needed. [I had raised this >> concern](https://github.com/openjdk/jdk/pull/23324#discussion_r2169217699), >> it went unanswered and marked as resolved. And I believe there's a new bug >> because of these static fields. > > If we have to call `WindowsMenuItemUI.paintMenuItem` from > `WindowsCheckBoxMenuItemUI`, `WindowsRadioButtonMenuItemUI`, `WindowsMenuUI ` > then `paintMenuItem `has to be static in `WindowsMenuItemUI` > so `paintAccText ` called from `paintMenuItem` has to be static so even if we > try to pass the parameters to `SwingUtilities3.paintAccText` from > `WindowsMenuItemUI.paintAccText ` those parameters need to be static else we > will be getting this kind of build error > > error: non-static variable disabledForeground cannot be referenced from a > static context > SwingUtilities3.paintAccText(g, lh, lr, disabledForeground, > acceleratorSelectionForeground, acceleratorForeground); I don't see the real code that you're referring to, but I strongly believe you can pass these colors as parameters. `WindowsMenuItemUI.paintMenuItem` isn't static and it has access to all the required colors inherited from `BasicMenuItemUI`, it calls a static method `paintMenuItem` as already passes background and foreground as parameters, therefore you could've added more parameters if they were needed. One way or another, you call these static methods from a non-static method — pass all the required parameters, maybe the `WindowsMenuItemUI` object itself to the static methods. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23324#discussion_r2269593938