Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8319103

Popups that request focus are not shown on Linux with Wayland

    XMLWordPrintable

Details

    • b25
    • generic
    • generic

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        Linux with Wayland

        A DESCRIPTION OF THE PROBLEM :
        If using components in JPopupMenu that request/receive focus (e.g. text field or button),
        then the popup is not shown. (it is made visible, but immediately hidden).

        Occurs only if the popup does not fit into invoker window.
        In this case a heavy-weight popup is used, which means that the popup is shown in another JWindow.
        When the popup JWindow gains focus, the invoker window looses focus and closes the popup.

        This is a regression in Java 21 caused by fix for JDK-8280993

        REGRESSION : Last worked in version 20


        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import javax.swing.*;
        import javax.swing.event.*;

        public class LinuxWaylandJava21PopupTest
        {
            public static void main( String[] args ) {
                SwingUtilities.invokeLater( () -> {
                    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( null, 0, showPopup.getHeight() );
                    } );
                    frame.add( showPopup );

                    frame.add( new JLabel( "Java version " + System.getProperty( "java.version" ) ), BorderLayout.NORTH );
                    frame.pack();
                    frame.setVisible( true );
                } );
            }
        }

        ---------- END SOURCE ----------

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                azvegint Alexander Zvegintsev
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: