On Fri, 5 Jul 2024 10:54:19 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
> > > This changeset enables hiding / showing mnemonics on JMenuBar only. Do > > > you plan to update ButtonUI and LabelUI for GTK Look-and-Feel too? > > > > > > Not as a part of this PR. It can be taken up as other bug. > > Does it make sense to handle mnemonics in buttons and labels as a separate > bug? I doesn't seem worth it. > > You've done 98% of the job in this PR. Refactoring touched all the classes > which hide mnemonics. > > The only thing left is to add handling into `SynthButtonUI` and > `SynthLabelUI` where you need to replace `b.getDisplayedMnemonicIndex()` and > `label.getDisplayedMnemonicIndex()` with a conditional display based on > `MnemonicHandler.isMnemonicHidden()`. I still think it is better to include mnemonics for buttons and labels in this PR. It could be done easily by the following diff: diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java index befa65d095e..514bfe400a5 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java @@ -361,7 +361,9 @@ public void paintText(SynthContext ss, Graphics g, String text, FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); y += fm.getAscent(); SwingUtilities2.drawStringUnderlineCharAt(c, g, text, - mnemonicIndex, x, y); + MnemonicHandler.isMnemonicHidden() + ? -1 : mnemonicIndex, + x, y); } } I [committed it as 7c70b20](https://github.com/aivanov-jdk/jdk/commit/7c70b20b7928fe21d262e7b229d37a6373876cee) on top of the latest version in this PR. The diff modifies the generic `SynthGraphicsUtils.paintText` so that no mnemonic is passed to `SwingUtilities2.drawStringUnderlineCharAt` if `isMnemonicHidden` returns `true`. This approach has *a performance impact* on all UI text painting. The condition can be moved into `GTKGraphicsUtils` so that only GTK L&F will call `isMnemonicHidden`. ------------- PR Comment: https://git.openjdk.org/jdk/pull/18992#issuecomment-2211244902