Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching GUI to System does not work #112

Open
JamesOlvertone opened this issue Nov 19, 2021 · 10 comments
Open

Switching GUI to System does not work #112

JamesOlvertone opened this issue Nov 19, 2021 · 10 comments

Comments

@JamesOlvertone
Copy link

JamesOlvertone commented Nov 19, 2021

Tested under Linux with different JDKs:
Switching the GUI to "system" stays always in Swing-Design. Seems that System under Linux is not GTK, it is Metal (Ocean).

I wrote a test programm that beave the same:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
sets the GUI to Metal.

There should be an Gtk Option and an additional "Nimbus" Option, Nimbus looks better than Metal or Gtk.

Nimbus:
It is recommended that this is not set explicit like the others. You have to get a list of LnFs and then choose it if it exists:
https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
           UIManager.setLookAndFeel(info.getClassName());
            break; 
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}

Gtk can be set like this:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");

But bec. it is not available on every platform it should be set like Nimbus above and the Dialog should be dynamically created
and offer only the options that are available on the platform.

And add this after setting the LnF:
SwingUtilities.updateComponentTreeUI( yourJFramewindowRef);
then no restart after change needed.

Yes I know LnF can be set on command Line and in pref-files.

@zlatinb
Copy link
Owner

zlatinb commented Nov 19, 2021

Are you trying a specific tag or the latest from git? I've added about 12 new look-and-feels since the 0.8.10 release

If you are running the .zip distribution, the System look and feel will not work on JDK 16 or 17 unless you edit the start script to add the following JVM option:

--add-opens java.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED

JDK 11 however should work without adding that option. Also, can you try if an AppImage works?

Thanks for the tip about removing the need to restart. I'm afk from my dev workstation until December but will look into it afterwards.

@JamesOlvertone
Copy link
Author

JamesOlvertone commented Nov 20, 2021

My test above was with the zip-version 0.8.10. Tested it with Open-JDK 11.0.2 and some others, no difference.
In the GUI-Dialog appear only three RadioButtons: System, Darcula, Metal.
Darcula works.

Now the new test with your option above:
Tested on the 0.8.10.zip Release and AppImage,
both with a clean .config/MuWire on an jdk 11.

Added the above line to the MuWire-startupscript:
DEFAULT_JVM_OPTS='"-Djava.util.logging.config.file=logging.properties"
"-Xms768M" "-XX:+HeapDumpOnOutOfMemoryError"
"-XX:+ExitOnOutOfMemoryError"
"--add-opens" "java.base/java.lang=ALL-UNNAMED"
"--add-opens" "java.base/sun.nio.fs=ALL-UNNAMED"
"--add-opens" "java.base/java.nio=ALL-UNNAMED"
"--add-opens" "java.desktop/java.awt=ALL-UNNAMED"
"--add-opens" "java.desktop/javax.swing=ALL-UNNAMED"
"--add-opens" "java.desktop/javax.swing.plaf.basic=ALL-UNNAMED"
"--add-opens" "java.desktop/sun.swing=ALL-UNNAMED"
"--add-opens" "java.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED"
'

After this I have the same options in the config dialog: System, Darcula, Metal
"System" was set but the LnF is Metal, like before.

Where can I select from the 12 Themes?

@zlatinb
Copy link
Owner

zlatinb commented Nov 20, 2021

To get the new themes you need to build the latest from git. However nothing has changed in the way the System theme is loaded, and I'm puzzled as to why it isn't working.

When you launch the start script with JDK 11, are there any warnings in the terminal?

@JamesOlvertone
Copy link
Author

JamesOlvertone commented Nov 20, 2021

No, no warnings.

I tried the latest from github.
Ah, here we go, a drop down with all the themes, no GTK or Nimbus appears in the list.
The themes that are included seem all to work (didnt try all): Luna, Fast, ...

Lets add again
-add-opens" "java.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED
in the start up script: Does not list GTK in the theme-drop-down.

Tried to set it explicit in .config/MuWire/gui.properties:
lnf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

Works! But does not appear in the theme drop down.

Nimbus:
Startup script:
"--add-opens" "java.desktop/javax.swing.plaf.nimbus=ALL-UNNAMED"
.config/MuWire/gui.properties:
lnf=/javax.swing.plaf.nimbus.NimbusLookAndFeel
Works! But does not appear in the theme drop down.

If anything is saved in the GUI-Dialog the set theme there is set for lnf=... in the gui.properties of course.

@zlatinb
Copy link
Owner

zlatinb commented Nov 20, 2021

Ok this does give me some clues as to what may be happening. The drop down menu is statically created and the System lnf is an alias for GTK on Linux, Aqua on Mac and Windows on Windows.

Can you tell me more about which distribution you are using and which desktop environment? That way I should be able to reproduce in a virtual machine.

@JamesOlvertone
Copy link
Author

JamesOlvertone commented Nov 20, 2021

XUbuntu 20.04.3 LTS, xfce Desktop.

There is another strange thing with Swing and GTK-LnF:
To get a list which LnFs are available there is javax.swing.UIManager.getInstalledLookAndFeels().
It returns LookAndFeelInfo Objects on each you can call getName() or getClassName().
getName() gives something like "Nimbus" or "Metal" and is the same what UIManager.getLookAndFeel.getName() returns.
So you can check the list before setting a LnF if it is available.

But on GTKLnF they are different:
UIManger.getLookAndFeel().getName(): "GTK look and feel"
LookAndFeelInfo.getName(): "GTK+"

So maybe someone checks the available list with the name by "GTK+" to see if GTKLnF is there, this does not match if you use String.equals() what you normaly do because all other names are the same as you expect.
I think thats why GTKLnF often does not work in other Javaprograms I noticed and wondered why always there is a problem with GTK-LnF.

@zlatinb
Copy link
Owner

zlatinb commented Dec 24, 2021

Hi, in the commit referenced above I made it possible to change theme settings without restart. Also, the way the "System" theme is applied was changed, so please test and let me know if the GTK theme works correctly.

A known issue is that if you have multiple MuWire windows open the theme change will get applied only to the main frame. That means the "MuWire is shutting down..." dialog will not get themed, nor will any open message composing windows, etc.

@JamesOlvertone
Copy link
Author

JamesOlvertone commented Dec 26, 2021

Works:
Acryl
Bernstein
HiFi
Noire
System -> uses Metal !!!
Aero
Texture

Works not: nothing happens when clicking on save, dialog does not close, gui does not change
Aluminium
Metal

Suggestions:

  • Add Nimbus
  • Sort the entries in the themes drop down list.

zlatinb added a commit that referenced this issue Dec 26, 2021
* Fix Aluminium LnF
* Add Nimbus, Metal, Motif and some system LnFs by name
* Sort list of LnFs
* Check if an LnF is available on the classpath on startup
@zlatinb
Copy link
Owner

zlatinb commented Dec 26, 2021

In the commit referenced above I implemented all the suggestions and fixed Aluminium and Metal. Also on your system there should be a GTK look and feel available in the drop-down menu. Please test.

@JamesOlvertone
Copy link
Author

Sorry for late answer I was ill+busy.
Thank you very much. I tested it and all works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants