B4J Question [Linux] Change application name instead of java main class name displayed on gnome panel

aeric

Expert
Licensed User
Longtime User
Hi, I want to change the java class name displayed on Linux desktop (Gnome) panel to show Application name instead.
I have tried many ways but still not succeed.
->
B4X:
    Dim Application As JavaObject = Me.As(JavaObject).InitializeStatic("com.sun.glass.ui.Application")
    Application.RunMethodJO("GetApplication", Null).RunMethod("setName", Array(ApplicationName))

B4X:
Dim stage As JavaObject = MainForm.As(JavaObject).GetFieldJO("stage")
stage.RunMethod("setTitle", Array(ApplicationName)) ' Set the window title

ChatGPT and DeepSeek giving the answer to use WM_CLASS and WM_NAME but I am not sure what is the correct way.

I also tried adding StartupWMClass into myapp.desktop file.
INI:
[Desktop Entry]
Name=MyApp
Type=Application
Categories=Utility;
Exec=/opt/myapp/run.command
Icon=/usr/share/icons/myapp/icon.png
StartupWMClass=com.company.myapp.main

There is another answer of using jna and x11 helper. I don't understand either.
Please help.
 
Last edited:
Solution
As Erel said at post#4, you may add native library for that



B4X:
#AdditionalJar: teddyx11

    Root = Root1
    Root.LoadLayout("MainPage")
    Dim jo As JavaObject=Me
    jo.InitializeNewInstance("teddy.x11.WindowManager",Null)
    If jo.GetField("notload") Then
        Log("notloaded")
    Else
        jo.RunMethod("setAppName", Array("Your APP"))
    End If


Project and library are attached.
It's only for b4j(jfx) and tested in ubuntu 18(x86) + gnome.

peacemaker

Expert
Licensed User
Longtime User
Deepseek told:

To ensure your Java application has a proper title, you should explicitly set the title of the window.

Stage stage = new Stage();
stage.setTitle("My Application Title");
stage.setScene(new Scene(new Group(), 300, 200));
stage.show();

And compare the Release mode.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
A silly workaround: the package name is not important. Set it to Application.Name.

I wouldn't add JNA calls just for this.

So this is what I needed?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
As Erel said at post#4, you may add native library for that



B4X:
#AdditionalJar: teddyx11

    Root = Root1
    Root.LoadLayout("MainPage")
    Dim jo As JavaObject=Me
    jo.InitializeNewInstance("teddy.x11.WindowManager",Null)
    If jo.GetField("notload") Then
        Log("notloaded")
    Else
        jo.RunMethod("setAppName", Array("Your APP"))
    End If


Project and library are attached.
It's only for b4j(jfx) and tested in ubuntu 18(x86) + gnome.
 

Attachments

  • Project.zip
    8.4 KB · Views: 18
  • gnome.zip
    4.5 KB · Views: 18
Last edited:
Upvote 1
Solution

aeric

Expert
Licensed User
Longtime User

I get the following error in Logs.
Failed to load library: no WindowManager in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
I copied libwindowmanager.so into /usr/lib and it works in Debian Linux.
It prints "App Name Your APP" in Logs when the app exits.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Did you copy the so to /usr/lib and chmod +x for it?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
It works in XUI Views Example, I only tested the 2 examples
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Maybe because I load Splash screen form and reload layouts.
edit: I need to call MainForm.Show and it is working now.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
I also tried adding StartupWMClass into myapp.desktop file.
INI:
StartupWMClass=com.company.myapp.main
This actually works.

Here is my modified instructions from AI chatbot:
  1. Create myapp.desktop file with content looks like the following using a Text editor.
    INI:
    [Desktop Entry]
    Name=MyApp
    Comment=My B4J JavaFX Application
    Exec=/path/to/myapp/run.command
    Icon=/path/to/icons/myapp/icon.png
    Terminal=false
    Type=Application
    Categories=Utility;
    StartupWMClass=com.company.myapp.main
  2. Place this file in the following location:
    • For just your user: ~/.local/share/applications/myapp.desktop
    • System-wide: /usr/share/applications/myapp.desktop
  3. Make sure the file has execute permissions:
    Bash:
    chmod +x ~/.local/share/applications/myapp.desktop
  4. Update the desktop database:
    Bash:
    update-desktop-database ~/.local/share/applications
    Optional: You can verify the WM_CLASS of your application by running this command in a terminal:
    Bash:
    xprop WM_CLASS
    Then click on your running B4J application window. It should show something like:
    Bash:
    WM_CLASS(STRING) = "com.company.myapp.main", "com.company.myapp.main"
  5. The app is now available in the Application drawer.
  6. Optional/Recommended: Copy the myapp.desktop to desktop. Right click and select "Allow Launching" (Debian Gnome).
User can now double click on the desktop icon to run the app and the panel is now showing the app name "MyApp".
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…