API addition proposal -- Add Action enum and methods to javafx.application.Application
David Kopp
codebangusllc at gmail.com
Mon Oct 14 14:48:20 UTC 2024
My personal preference would be to make the existing java.awt.Desktop class work correctly with JavaFX. I know the MacOS build of JavaFX requires the java.desktop module anyway.
APP_ABOUT and APP_PREFERENCES are only supported on MacOS. They were added to provide a public API to replace the old com.apple classes.
My approach in my JavaFX test app was to call SwingUtilities.invokeLater to interact with the java.awt.Desktop methods. The event handler will of course need to use Platform.runLater, but that is fine.
Perhaps adding a static initializer to call Thread t = new Thread(() -> { java.awt.Toolkit.getDefaultToolkit(); }); t.start(); that only runs on MacOS?
Have a blessed day,
David
> On Oct 12, 2024, at 7:44 PM, Michael Hall <mik3hall at gmail.com> wrote:
>
>
>
>> On Oct 12, 2024, at 9:35 AM, David Kopp <codebangusllc at gmail.com> wrote:
>>
>> Hello everyone,
>>
>> I develop cross platform JavaFX applications. On MacOS one of the annoying things about JavaFX is that it does not provide a way to add About <<app_name>> and Settings… to the application menu bar like the java.awt.Desktop class does in Swing.
>>
>> My proposal is to add similar functionality to JavaFX. I propose adding the following to javafx.platform.Application:
>>
>
>
>
>> On Oct 12, 2024, at 9:35 AM, David Kopp <codebangusllc at gmail.com> wrote:
>>
>> Hello everyone,
>>
>> I develop cross platform JavaFX applications. On MacOS one of the annoying things about JavaFX is that it does not provide a way to add About <<app_name>> and Settings… to the application menu bar like the java.awt.Desktop class does in Swing.
>>
>
> It would be convenient. Recently I wanted to check that I was current with Scene Builder, but there was no about item with the version.
>
> I looked at this some time back.
>
> https://marc.info/?l=openjdk-openjfx-dev&m=167391490829873&w=2
>
> I did this, incomplete as a lot of my stuff is, after the following note.
>
> https://github.com/mik3hall/JavaFXDesktop
>
> On Jan 6, 2023, at 4:35 PM, Michael Hall <mik3hall at gmail.com> wrote:
>
> I haven’t verified if this would further allow changing the java.awt.Desktop about handler.
>
> I did check that custom AboutHandlers are possible for OS/X JavaFX applications.
> With…
>
> static {
> //java.awt.Toolkit.getDefaultToolkit(); // Start AppKit
> Thread t = new Thread(() -> { java.awt.Toolkit.getDefaultToolkit(); });
> t.start();
> }
>
> I made the Application class itself the handler…
>
> public class HelloWorld extends Application implements AboutHandler {
>
> Setting the handler seemed to also need some thread management.
>
> @Override
> public void init() {
> Thread t = new Thread(() -> {
> Desktop desktop = Desktop.getDesktop();
> desktop.setAboutHandler((AboutHandler)this);
> });
> t.start();
> }
>
> It appeared this could be done in the init or about anywhere in the javaFX start method.
>
> The handler I think comes in on the AWT EventQueue so needs to be changed to javaFX
>
> public void handleAbout(AboutEvent evt) {
> System.out.println("got to handleAbout");
> Platform.runLater(() -> {
> Alert alert = new Alert(AlertType.INFORMATION, "About HelloWorld");
> alert.showAndWait();
> });
> }
>
> Checking on Windows 10 VirtualBox it appeared Desktop.Action.APP_ABOUT isn’t supported.
> I had trouble with my VirtualBox linux images so didn’t verify there but I’m guessing this is viewed as OS/X only and not supported there either.
>
> I never really did determine why javaFX applications are different. My last thought had been that they instantiated an NSApplication early so a NSApplicationAWT wss never obtained. However, I later thought I saw where I passed a check indicating I had to have NSApplicationAWT. With a fix so you get the About menu item it seemed a little moot. What I provided for ApplicationDelegate seems to be one such fix. You can come up with your own fix but I think it will need to done jdk side though to provide this functionality to javafx app’s. I might bring this up on the javafx list if the jdk does make it possible at some point.
>
> I haven’t looked at any other Desktop functionality for javafx app’s yet having no immediate need myself.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20241014/a0fd3c87/attachment-0001.htm>
More information about the openjfx-dev
mailing list