10

Is there a way for a Java Swing desktop application that runs in Gnome (3.14) on Linux (Debian) to make Gnome use the dark-themed (Adwaita) version of the window decoration?

I am using a custom dark Swing look-and-feel, and the only thing that is really annoying is that the title bar (native Gnome) is very bright. I already have used the Tweak tool to use Adwaita system-wide, but this doesn't kick in for applications that do not explicitly support dark-theme (e.g. Iceweasel, Icedove, Gimp, Libre Office, ...)


Here's a screenshot that illustrates the problem:

enter image description here

0__
  • 66,707
  • 21
  • 171
  • 266
  • It's possible that the look and feel is rendering its own window decorations. It might be possible to confirm it,,but we'd need more information about the look and feel – MadProgrammer Mar 07 '16 at 20:25
  • @MadProgrammer - yes, but I would prefer to stick to the system native window decoration, because that determines how windows can be moved, docked, put-always-on-top etc. etc. – 0__ Mar 07 '16 at 20:30
  • If the look and feel is painting the decoration then it will take care of (some) of those things and you may or may not have any ability to control it, but that would come down to the look and feel you are using. You might consider having a look at [`JFrame#setDefaultLookAndFeelDecorated `](https://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#setDefaultLookAndFeelDecorated(boolean)) – MadProgrammer Mar 07 '16 at 20:40
  • @MadProgrammer thanks, I'm aware of `setDefaultLookAndFeelDecoracted`, I'm particularly asking for the case where this is `false` (the default). Other apps such as GEdit or Nautilus take advantage of using the Adwaita themed title bar. There must be a way for a Java application to trigger that flag somehow. – 0__ Mar 07 '16 at 21:09
  • As far as I know GEdit and Nautilus use GTK, not Swing, so their window decoration management is different – OneCricketeer Mar 16 '16 at 02:12
  • @cricket_007 Yes, but Swing is not a native Window Tk. At the very bottom it does use Gtk. As far as I understand, the main problem is it uses Gtk 2 not 3 (e.g. see http://openjdk.java.net/jeps/283) – 0__ Mar 16 '16 at 02:15
  • So you mean that without changing anything in the `JFrame` but with `Global Dark Theme` set in Tweak-Tool, the TitleBar is not dark? I have just tested this and my TitleBar is dark for a default `JFrame`. – MalaKa Mar 21 '16 at 14:58
  • @MalaKa yes. Apparently this happens to many applications (I mentioned Iceweasel, Icedove, Inkscape, Gimp) that are written against Gtk2 and not Gtk3. I tried installing an "adwaita-dark backported to Gtk2" that then appears in the Tweak tool. But it has no influence on the window decorations apparently. I don't know if there is any other way of hacking into this... In the meantime I have found information that suggests OpenJDK also uses Gtk2 not Gtk3. Perhaps one could use the java-gtk bindings to make it work? – 0__ Mar 21 '16 at 17:12

1 Answers1

4

Ok, I found a viable solution for my specific system, so I will show what I did here. It is related to this question. In the accepted answer you can see that the issue is with legacy Gtk-2 applications, and that includes Java apparently. In the comments section there is a link to a Adwaita-Dark clone that applies the dark theme also to Gtk-2.

Unfortunately that theme is out-of-sync with Debian Jessie / Gnome 3.14 somehow, and if one installs that theme most widgets are broken in Iceweasel, Icedove etc. However. Since I don't care about the widgets but only the window title bar here, you can selectively use that clone only for the window decoraction.

So I downloaded that clone, and placed a symlink in ~/.local/share/themes/adwaita-again (you can use any name here it seems). Then in the Tweak tool, just flip the window style, like so:

enter image description here

And voilà, window title bars are dark for all applications:

enter image description here

This is also great when working with IntelliJ IDEA and "Darcula" theme. Linux FTW.


Edit: It seems the above approach does not fully work, at least after rebooting I am seeing the bright colours again. I found a more simple variant now: Copy the original Adwaita theme and patch the Metacity file. I have created a repository with my patched version.

0__
  • 66,707
  • 21
  • 171
  • 266