JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.42k stars 272 forks source link

Freeze due to menu safe triangle event queue #870

Closed Chrriis closed 3 months ago

Chrriis commented 4 months ago

Hi!

I have an application that has its own event queue. This event queue must be the active event queue or else the application freezes. Unfortunately, when I show a menu under FlatLaf, the application freezes due to the safe triangle feature and its custom event queue.

Thus, I would like to deactivate the safe triangle feature, but I cannot change the code of the application.

Related: https://github.com/apache/netbeans/issues/4231 https://github.com/JFormDesigner/FlatLaf/pull/490

Cheers, -Christopher

DevCharly commented 4 months ago

Is there a way to force "Menu.useSafeTriangle=false" using system properties?

no

Is there a way to use a theme properties file which path is defined by a system property?

no

What you could do is use your own main method, disable safe triangle, and invoke application main method. E.g.

class MyApp {
    public static void main( String[] args ) {
        UIManager.put( "Menu.useSafeTriangle", false );
        com.application.App.main( args );
    }
}

Hint: Newer Java versions can execute single .java files directly (without compiling).

Chrriis commented 4 months ago

Hi Karl, thanks for your fast answer as usual!

Unfortunately, I have limited possibilities... I can add system properties (and the product allows to set the look and feel through properties), I can alter the classpath, but I cannot change the way the main is invoked (hidden from me).

Would it be possible to add a system property to switch off this queue-interfering business? Or else FlatLaf will not be a viable option for me 😞

Cheers, -Christopher

DevCharly commented 4 months ago

I wonder what "product" you use?

Maybe it makes sense to disable this feature automatically if a custom event queue is used? But I'm not sure whether this would affect special environments. E.g. WebSwing

Chrriis commented 4 months ago

I wonder what "product" you use?

It is a legacy application that has its own launcher (exe).

Maybe it makes sense to disable this feature automatically if a custom event queue is used?

Hard to tell, I am not sure if having a custom event queue necessarily means that yours will freeze the application?

So, as a first step, I think it would make sens to have a way to switch it off... don't you agree? 😉

DevCharly commented 4 months ago

Ok, I'll add a system property in the next release.

If you need a solution now, remove following line and build flatlaf-core:

https://github.com/JFormDesigner/FlatLaf/blob/d510fee7f6b3c05c323ed4560d7dde2190cefa02/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java#L265

Chrriis commented 4 months ago

Thanks, but I cannot use unofficial versions of FlatLaf...

Possible improvement to the properties logic: If no property is specified, then safe triangle feature is active only if there is no custom event queue. If a property is specified (sys prop and/or UIManager prop), then most restrictive is used.

It would prevent unexpected freezes due to custom event queues for users who have no idea what the problem could be. This would also allow someone with a custom event queue to activate the feature by setting the property to "=true".

DevCharly commented 3 months ago

implemented in latest 3.5.1-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

Added system property flatlaf.useSubMenuSafeTriangle to allow disabling submenu safe triangle. Also check whether EventQueue.push() succeeded; if not, disable submenu safe triangle.

Did not implement your suggestion because this would break some application that use FlatLaf (e.g. OpenPnP, jadx and Pixelitor). https://github.com/search?q=getSystemEventQueue%28%29.push&type=code

3.5.1 release is coming soon...

Chrriis commented 3 months ago

Hi Karl,

Thanks a lot for the system property!! 😃

Did not implement your suggestion because this would break some application that use FlatLaf

I am confused by this comment... Do you mean that you push your own queue even if a custom queue is already in place? Don't you think THAT is going to break the applications, since their queue will be ignored?

Also check whether EventQueue.push() succeeded

Good point!

DevCharly commented 3 months ago

Did not implement your suggestion because this would break some application that use FlatLaf

I am confused by this comment...

I meant that your suggestion would disable submenu safe triangle for existing applications that use FlatLaf and use a custom event queue.

Do you mean that you push your own queue even if a custom queue is already in place?

Yes, that has not changed. This is done since FlatLaf 2.1.

Don't you think THAT is going to break the applications, since their queue will be ignored?

Good question, but the FlatLaf submenu event queue is used only temporary for a short time while the mouse is over a JMenu that has submenus, or while moving within the safe triangle...

A (temporary) custom event queue was the only solution (to my knowledge) to catch and ignore mouse events while mouse is moving within safe triangle. And this is a huge usability improvement for submenus and IMHO worth the risk of temporary loosing some feature of a custom application event queue.

Chrriis commented 3 months ago

A (temporary) custom event queue was the only solution (to my knowledge) to catch and ignore mouse events

Hm, I wonder... Perhaps when a sub-menu is showing you could: