Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux with Wayland and Java 21: popups that request focus are not shown #752

Closed
DevCharly opened this issue Oct 21, 2023 · 1 comment
Closed
Milestone

Comments

@DevCharly
Copy link
Collaborator

On Linux with Wayland, since Java 21, Swing adds a window focus listener
to popup owner/invoker window, which hides the popup as soon as the owner window looses focus.
This works fine for light-weight popups (because they use JPanel).
It also works for heavy-weight popups (which use JWindow) if the do not request focus (e.g. menus, tooltips, combobox list).
Because FlatLaf always uses heavy-weight popups, all popups that request focus are broken since Java 21.

JDK bug and PR that cause the problem:

Test case to reproduce the issue:

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import com.formdev.flatlaf.FlatLightLaf;

public class LinuxWaylandJava21PopupTest
{
    public static void main( String[] args ) {
        SwingUtilities.invokeLater( () -> {
            FlatLightLaf.setup();
            JFrame frame = new JFrame( LinuxWaylandJava21PopupTest.class.getSimpleName() );
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

            JButton showPopup = new JButton( "show popup" );
            showPopup.addActionListener( e -> {
                JPanel popupPanel = new JPanel();
                popupPanel.add( new JTextField( 20 ) );

                JPopupMenu popupMenu = new JPopupMenu();
                popupMenu.add( popupPanel );
                popupMenu.addPopupMenuListener( new PopupMenuListener() {
                    @Override
                    public void popupMenuWillBecomeVisible( PopupMenuEvent e ) {
                        EventQueue.invokeLater( () -> {
                            // focus first component in popup
                            popupPanel.transferFocus();
                        } );
                    }
                    @Override
                    public void popupMenuWillBecomeInvisible( PopupMenuEvent e ) {
                        System.out.println( "popup will become invisible" );
                    }
                    @Override
                    public void popupMenuCanceled( PopupMenuEvent e ) {
                        System.out.println( "popup canceled" );
                    }
                } );
                popupMenu.show( showPopup, 0, showPopup.getHeight() );
            } );
            frame.add( showPopup );

            frame.add( new JLabel( "Java version " + System.getProperty( "java.version" ) ), BorderLayout.NORTH );
            frame.pack();
            frame.setVisible( true );
        } );
    }
}
DevCharly added a commit that referenced this issue Oct 21, 2023
@DevCharly
Copy link
Collaborator Author

fixed in 3.2.3

@DevCharly DevCharly added this to the 3.2.3 milestone Oct 21, 2023
DevCharly added a commit that referenced this issue Oct 21, 2023
…s `null` (only on Linux with Wayland and Java 21; regression in 3.2.3) (issue #752)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant