On Mon, 3 Aug 2026 06:10:09 GMT, Prasanta Sadhukhan <[email protected]> wrote:
> In Aqua L&F, JOptionPane.showInternalMessageDialog does not close after > clicking the close icon button but other buttons like "OK" , "Cancel" works. > It seems `AquaInternalFrameBorder.doButtonAction()` which handles > `kCloseButton `was not called. > It is seen that `showInternalMessageDialog()` uses a modal JInternalFrame. > While that internal frame is modal, AWT filters mouse events so only the > modal frame’s contents/children can receive them. Aqua paints and handles the > red close button as part of the JInternalFrame border/title-bar itself via > AquaInternalFrameBorder. drawAllWidgets -> paintButton -> getWidget > (Widget.TITLE_BAR_CLOSE_BOX) > https://github.com/openjdk/jdk/blob/5b2d6991a1279d375f9a3c00c7bcd0bbcc7081d6/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java#L393 > > When close button is presssed, the flow should be > https://github.com/openjdk/jdk/blob/5b2d6991a1279d375f9a3c00c7bcd0bbcc7081d6/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java#L528 > [records the button hit which delegates to the border] > https://github.com/openjdk/jdk/blob/5b2d6991a1279d375f9a3c00c7bcd0bbcc7081d6/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java#L536 > > https://github.com/openjdk/jdk/blob/5b2d6991a1279d375f9a3c00c7bcd0bbcc7081d6/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java#L265 > > but it never gets called since > the click target was the modal JInternalFrame itself, not a child component, > so the modal filter consumed the event before Aqua code ever saw it, > > The fix is to allow events targeted at the modal component itself too > > It works for other L&F like Windows because they use Swing JButton for close > button component in the internal frame title pane. so the click target is a > child of the modal JInternalFrame, so the filter check is passed. > There doesn't seem to be a way to fix in macosx classes because Aqua never > receives the blocked event. The event is consumed earlier in shared AWT > lightweight-modal dispatch code so the fix is made there > CI testing is ok and no regression observed. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). Actually, `JOptionPane.createInternalFrame` creates the frame as closable as closable=true https://github.com/openjdk/jdk/blob/963ae29d5255d96a32f3c45aa8808bc6d3f947e3/src/java.desktop/share/classes/javax/swing/JOptionPane.java#L1522-L1523 so close button is enabled at start but `MetalInternalFrameTitlePane.MetalPropertyChangeHandler#updateOptionPaneState` explicitly turns closability off for option-pane message types: https://github.com/openjdk/jdk/blob/63808b08e156592458f759cbd2aa6ae9108735ae/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java#L562-L566 so close button is not visible for Metal but for Aqua, AquaInternalFrameUI creates AquaInternalFrameBorder to only change the border/style and leaves frame.isClosable() true https://github.com/openjdk/jdk/blob/63808b08e156592458f759cbd2aa6ae9108735ae/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java#L335-L336 We can modify `JOptionPane.createInternalFrame` call to have closable=false like other params to make them consistent in which case no close button will be visible for any L&F but I was not sure as that will cause L&F behavior change so I fixed for Aqua where close button is not working (for other L&F close button is already working) As of now, In Windows,Nimbus,Aqua close button is there and it works for Windows and Nimbus because they were swing JButton and it does not work for Aqua as the button is drawn For Metal and Motif close button is not there..I'm not sure if this is a bug, it seems to be the way each L&F looks different so I was considering and working on the premise that, if it is visible, the button should work and made the fix accordingly.. ------------- PR Comment: https://git.openjdk.org/jdk/pull/32169#issuecomment-5174404931
