B4J Library jFXSystemTrayHandler - Display a javafx context menu

Discussion in 'B4J Libraries & Classes' started by stevel05, May 6, 2018.

  1. stevel05

    stevel05 Expert Licensed User

    This is a code module that allows display of a JavaFX Context Menu when the system tray Icon is clicked.

    Used in conjunction with the MenuManager Library, it is possible to add checkbox items, images, Fontawesome and MaterialIcons and CustomItems to the contextmenu.

    You can compile it to a library if you prefer not to add the module to your project.

    Untested on a Mac or Linux, but please let me know.

    Demo app depends on:

    jSystemTray
    MenuManager
    JavaObject

    Update to 0.2 - Changed Form type to UTILITY - Confirmed working with MacOS

    14
     

    Attached Files:

    Last edited: Sep 5, 2018
    DonManfred, Mashiane, BPak and 3 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Nice job!

    I see that it creates a new form when clicked. Try to set its style to UTILITY. This will hide the task bar item from appearing each time.

    It works on Mac with a few issues:
    1. The form doesn't show on the first click.
    2. It doesn't hide automatically. Only when an item is selected. A possible workaround is to hide it when clicking on the icon itself.
    3. The menu can be hidden by other windows. It is not brought to front.
     
  3. stevel05

    stevel05 Expert Licensed User

    Thanks Erel, I'll try and boot up an old Mac I have tomorrow (if it still works). I think it'll run java 8.
     
  4. stevel05

    stevel05 Expert Licensed User

    Finally got something working on Mac, Running Mavericks and java 1.8.0_171 it seems to work the same as on the PC.

    What OS and java versions are you testing it on?
     
    Peter Simpson and Erel like this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    Mac 10.13.4 with Java 8.
     
  6. stevel05

    stevel05 Expert Licensed User

    Fixing the mac implementation has stalled for the moment as I haven't been able to get access to a more recent system. I'm working till after the weekend, I'll look at it again next week.
     
  7. stevel05

    stevel05 Expert Licensed User

    OK, finally got it to fail on Mavericks, would you believe that setting the form type to UTILITY changed the behaviour?. So as originally released with form set to TRANSPARENT, it exhibits the issues that Erel reported, set to UTILITY, it doesn't. And of course I made that change before I tested it on Mavericks.

    So would someone be so kind as to test this version, the only change is the form type and see if that does actually work properly on a newer OS than Mavericks.

    What should happen:
    • Click on the orange icon in the icon bar (don't know what it's called in MacOS) and the menu is displayed.
    • Click anywhere not on the menu, the menu is closed
    • Click on an option, the option is logged and the menu closes.
    • Click on a sub menu the sub menu opens
      • If a sub menu is open then
        • Click anywhere not on the menu, the menu is closed
        • Click on an option, the option is logged and the menu closes.

    Thanks

    Edit: File moved to first post
     
    Last edited: May 12, 2018
    Erel, BPak and Johan Hormaza like this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    Looks good!
     
    stevel05 likes this.
  9. stevel05

    stevel05 Expert Licensed User

    Thanks Erel.

    I have moved the file to the first post.
     
    Peter Simpson likes this.
  10. stevel05

    stevel05 Expert Licensed User

    For completeness, I tried to test this on Ubuntu, but apparently the system tray was removed a few releases ago, so it is not currently supported. It is possible to jump through some hoops to re-install it but I don't want to go there. If anybody tries in on flavours of Linux that supports the system tray, please let me know the results.
     
  11. Blueforcer

    Blueforcer Active Member Licensed User

    On mac opening the Traymenu wont work when you pack the app with B4J Packager. It crash
    This is the same problem as mentioned here:
    https://www.b4x.com/android/forum/threads/problem-with-b4jpackager.96667/#post-609919

    If i set the Owner of the STForm (in FXSystemTrayHandler) to the Mainform, it works. But only if the Mainform is visible.
    But of course i want to hide the Mainform, to use the Tray ;)

    is there a way to solve this?
     
  12. stevel05

    stevel05 Expert Licensed User

    Does it work as expected if you run the jar file without packaging it?
     
  13. Blueforcer

    Blueforcer Active Member Licensed User

    Yes.
    Maybe because i run Java 10, and the packager packing java 8 wich still has this problem
     
    Last edited: Sep 23, 2018
  14. stevel05

    stevel05 Expert Licensed User

    Hmm, the work around given in the JDK bug report would still leave an icon in the task bar, which is not what you want. I guess it's not going to do what you want until the packager allows the use of java 10.
     
  15. Blueforcer

    Blueforcer Active Member Licensed User

    yes i think so too, ive opened a new thread for that.
    For now i will publish my App as the raw Jar file for MacOS.
    Thank you anyway
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice