mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

WebMenu flashes #607

Open husker-dev opened 4 years ago

husker-dev commented 4 years ago

WebMenu flashes when mouse enter into parent menu. It is strange that it does not blink if the mouse exit WebMenuItem. I think this is due to the arrow icon.

menu

mgarin commented 4 years ago

It actually has nothing to do with arrow - it just so happens that arrow is positioned exactly around the location where menu shadow ends, meaning that cursor is actually leaving popup menu bounds only after going away for more than 8px (current shadow width).

Also this only seem to happen when you're leaving JPopupMenu that has selected JMenu (and it's own JPopupMenu open), you can check it on example below.

Also, this isn't WebLaF-specific issue:

public class MenuTest
{
    public static void main ( final String[] args )
    {
        SwingTest.run ( MetalLookAndFeel.class.getCanonicalName (), new Runnable ()
        {
            @Override
            public void run ()
            {
                final JButton button = new JButton ( "Show menu" );
                button.addActionListener ( new ActionListener ()
                {
                    @Override
                    public void actionPerformed ( final ActionEvent e )
                    {
                        final JPopupMenu menu = new JPopupMenu ();

                        final JMenu subMenu = new JMenu ( "New" );
                        menu.add ( subMenu );

                        final JMenu subSubMenu = new JMenu ( "Style" );
                        subMenu.add ( subSubMenu );

                        final JMenu subSubSubMenu = new JMenu ( "Sub" );
                        subSubSubMenu.add ( new JMenuItem ( "Item 1" ) );
                        subSubSubMenu.add ( new JMenuItem ( "Item 2" ) );
                        subSubMenu.add ( subSubSubMenu );
                        subSubMenu.add ( new JMenuItem ( "Other" ) );

                        menu.show ( ( Component ) e.getSource (), 0, button.getHeight () );
                    }
                } );
                TestFrame.show ( button, 150 );
            }
        } );
    }
}

Same is happening with Metal, Nimbus and other L&Fs, seemingly on any Java version - tested on 6, 8, 9, 11 and 13.

This is surely a weird behavior, but I believe it has something to do with the subsequent menus closing the same time you switch from sub-menu to it's parent menu.

This might be fixable through a complete rework of the underlying UIs (I haven't touched menus so far, they use default implementations), but this will take some time and isn't as high priority as a lot of other things that lack some styling features or straight up have bugs. So I'll probably postpone this until some later updates.

mgarin commented 4 years ago

Also I weren't able to find any open or closed JDK issues for this, probably no one noticed this or at least didn't really bother to report this. Or it just has some weird description that is difficult to find.