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

WebPopupMenu resets preferred display position after it becomes visible #603

Closed mgarin closed 4 years ago

mgarin commented 4 years ago

Originally reported by @husker-dev via email.

Here is a code example displaying the issue:

public class MenuTest
{
    public static void main ( final String[] args )
    {
        SwingTest.run ( new Runnable ()
        {
            @Override
            public void run ()
            {
                final WebPopupMenu menu = new WebPopupMenu ();
                menu.setPopupMenuWay ( PopupMenuWay.belowEnd );
                menu.add ( new WebMenuItem ( "Item" ) );

                final WebButton button = new WebButton ( "Show menu" );
                button.addActionListener ( new ActionListener ()
                {
                    @Override
                    public void actionPerformed ( final ActionEvent e )
                    {
                        // menu.setPopupMenuWay ( PopupMenuWay.belowEnd );
                        menu.show ( button, -button.getWidth () / 2, button.getHeight () );
                    }
                } );

                TestFrame.show ( button );
            }
        } );
    }
}

If the commented line of code is uncommented - menu will always be displayed correctly.

This technically isn't a bug because originaly I intended PopupMenuWay (probably should be renamed in future to something better as well) to be a one-time use setting. And that is how it basically works in current version.

Although this is surely not convenient and, realistically, you would rarely need to change this setting in actual use cases. So it is worth preserving it over multiple displays of the same popup menu.

mgarin commented 4 years ago

I've changed the code to preserve the setting. This change will shortly be available in v1.2.12 snapshot artifacts.