On Fri, 7 Aug 2026 16:50:41 GMT, eduardsdv <[email protected]> wrote:
> This PR fixes the StringIndexOutOfBoundsException, that occurs when an empty
> text is set to a Labeled, that previously contained a mnemonic.
>
> The reason for the error is that the ``updateDisplayedText(double, double)``,
> which also updates ``containsMnemonic`` flag, was not invoked if the text was
> empty. The value of this flag was still ``true`` but the index of the
> mnemonic character inside ``MnemonicInfo`` had already been updated to -1.
> This led to the StringIndexOutOfBoundsException in the line 611.
>
> I fixed it by moving the call to ``updateDisplayedText(double, double)``
> outside the if-clause, so that it is always called when the text is being
> laid out. This should not affect performance because the method already
> checks whether recalculation is required. If not, it exits quickly.
>
> ---------
> - [X] I confirm that I make this contribution in accordance with the [OpenJDK
> Interim AI Policy](https://openjdk.org/legal/ai).
Changes requested by arapte (Reviewer).
modules/javafx.controls/src/main/java/javafx/scene/control/skin/LabeledSkinBase.java
line 560:
> 558: text.setText("");
> 559: } else {
> 560: textWidth =
> snapSizeX(Math.min(text.getLayoutBounds().getWidth(), wrapWidth));
`ignoreText` would be true in two cases, either
- when the text is empty / null or
- `ContentDisplay.GRAPHIC_ONLY` is true. refer [
LabeledSkinBase.isIgnoreText()](https://github.com/openjdk/jfx/blob/3b54913c53f5ac079278a934081d87ce7d55173f/modules/javafx.controls/src/main/java/javafx/scene/control/skin/LabeledSkinBase.java#L1241)
With this change, `updateDisplayedText()` gets invoked unconditionally even for
the scenario when the text is non-empty, but needs to be ignored because
`ContentDisplay.GRAPHIC_ONLY` is true.
Please check if this can cause any issue.
-------------
PR Review: https://git.openjdk.org/jfx/pull/2253#pullrequestreview-4950175974
PR Review Comment: https://git.openjdk.org/jfx/pull/2253#discussion_r3795188164