RFR: 8355203: [macos] AquaButtonUI and AquaRootPaneUI repaint default button unnecessarily

Jeremy Wood duke at openjdk.org
Wed Apr 23 05:18:41 UTC 2025


On Wed, 23 Apr 2025 03:37:01 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> src/java.desktop/macosx/classes/apple/laf/JRSUIConstants.java line 197:
>> 
>>> 195:         public static final State PRESSED = new State(_pressed);
>>> 196:         @Native private static final byte _pulsed = 5;
>>> 197:         public static final State DEFAULTBUTTON = new State(_pulsed);
>> 
>> Is it still necessary to use the pulse property from JRS, or can we treat this button like any other and rely on the standard active/inactive state?
>
> or default button appearance is different?

If I understand your question, I think the answer is:

Yes, the State.DEFAULTBUTTON constant is necessary for default JButtons to render correctly.

In case I misunderstood the question here is some additional context:

The only place `DEFAULTBUTTON` is referenced is here:

    protected State getButtonState(final AbstractButton b, final ButtonModel model) {
        if (!b.isEnabled()) return State.DISABLED;

        // The default button shouldn't draw its color when the window is inactive.
        // Changed for <rdar://problem/3614421>: Aqua LAF Buttons are incorrectly drawn disabled
        // all we need to do is make sure we aren't the default button any more and that
        // we aren't active, but we still are enabled if the button is enabled.
        // if we set dimmed we would appear disabled despite being enabled and click through
        // works so this now matches the text drawing and most importantly the HIG
        if (!AquaFocusHandler.isActive(b)) return State.INACTIVE;

        if (model.isArmed() && model.isPressed()) return State.PRESSED;
        if (model.isSelected() && isSelectionPressing()) return State.PRESSED;
        if ((b instanceof JButton) && ((JButton)b).isDefaultButton()) return State.DEFAULTBUTTON;

        return State.ACTIVE;
    }


I tried removing the line that returned `DEFAULTBUTTON`, but then the test attached to this PR failed; the default button rendered like a generic Aqua JButton. So we still need some mechanism to make sure default buttons paint correctly. In this branch: that mechanism is State.DEFAULTBUTTON.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24778#discussion_r2055262099


More information about the client-libs-dev mailing list