X
X
Xintrea2011-07-02 22:39:36
Java
Xintrea, 2011-07-02 22:39:36

How to change the theme in an arbitrary Java application?

Hello!

I am a complete layman in Java, just a user. But I want to figure it out once and for all: how to change and customize themes in Java applications? And is it possible to do this if the Java application itself does not provide for work with themes?

For example, I use the NetBeans IDE. In it, you can only customize the appearance of the code editing area. And you can’t customize the theme of the entire NetBeans - the color of the frames, the lines in the trees, the fonts - you can’t. And I, for example, need to change the color of all Java frames. How to do it?

The only thing I dug up is the use of the Java option --laf. For example, you can start NetBeans with this command:

./netbeans --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel


The --laf option will be passed to the java environment and NetBeans will start with the GTK interface. But here a few questions arise:

1. How can I find out the names of the available interface themes? I dug up only the above title.

2. How do I customize the color scheme for the selected theme? Is it possible in principle?

And another question. I found the TinyLaf program: www.muntjak.de/hans/java/tinylaf/index.html . It generates *.theme files. Can these themes be used in an arbitrary Java program such as NetBeans? How to connect them?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
mardy_bum, 2011-07-02
@mardy_bum

1. This simple code will display the lafs installed in the system

import javax.swing.UIManager;

public class Plaf {
    public static void main(String[] args) {
    UIManager.LookAndFeelInfo plaf[] = UIManager.getInstalledLookAndFeels();
       for (int i = 0; i < plaf.length; i++)
          System.out.println(plaf[i].getName() + "\n" + plaf[i].getClassName());
    }
}

The choice isn't really great. There are only 4 themes available on my Mac: 2. It's possible, but as far as I know there is no easy way. You will have to manually dig into the code and edit each element of the theme. Although I heard that the Nimbus theme allows you to change the color scheme, I have not tried it myself. About TinyLaf. You are lucky, the software is well documented, read the docs. The readme file described the process of connecting themes.
Metal
javax.swing.plaf.metal.MetalLookAndFeel
Nimbus
com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
CDE/Motif
com.sun.java.swing.plaf.motif.MotifLookAndFeel
Mac OS X
com.apple.laf.AquaLookAndFeel

X
Xintrea, 2011-07-02
@webhamster

> 1. This simple code will display the lafs installed in the system. Did
n't understand what a normal user should do with this code? Do you need to compile? Doesn't the java program have a ready-made command or option?
.
> Although I heard that the Nimbus theme allows you to change the color scheme, but I have not tried it myself.
Hmm, so it allows or not? How? Google is silent. It seems that the exact science of computer science has turned into magic: it may be possible, but no one knows.
.
>About TinyLaf. You are lucky, the software is well documented, read the docs. The readme file described the process of connecting themes.
I did not find a description of the process of connecting themes to a third-party Java application there. It only describes how to connect to the code/assembly.

B
bald2b, 2011-07-03
@bald2b

The person just asks how to change themes in any application :) You need to pass the swing.defaultlaf
parameter to the java program, for example java -jar -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel myApp.jar If the theme comes from a third-party jar, then the jar must be in the classpath

K
KhanTengri, 2011-07-03
@KhanTengri

In general, I do not see a serious problem in this ...
First of all, I will say that it makes no sense to receive a list of existing topics.
For each specific jdk version, they are always and everywhere the same.
For example, for jdk6, as already written above, they will be like this:

metal
javax.swing.plaf.metal.MetalLookAndFeel
Nimbus
com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
CDE/Motif
com.sun.java.swing.plaf.motif.MotifLookAndFeel

The only exception is Mac, where the theme is added:
MacOS X
com.apple.laf.AquaLookAndFeel

All other themes like Alloy, Stubstance, Synthetica etc. you add yourself, by hand.
Specifically to your question...
I don't think that these color changes that you want to do can be made as parameters at startup.
All changes in the colors of frames, backgrounds, etc. It's all interface customization.
For an example, you can take a look at the Metalworks application that comes with all Oracle jdks.
You can find it here: <JAVA_HOME>/demo/jfc/Metalworks/Metalworks.jar Take a
look at the code (in the folder next to it) and you will see that all the color schemes are written there manually (by calling methods or reading your own configs)
The best option for you, in my opinion, is to write your own class that extends one of the themes, for example, javax.swing.plaf.metal.MetalLookAndFeel and write there what color frame you need. Alternatively, you can write this class in such a way that it simply reads the adjacent properties file. This will give you the ability to easily change colors without recompiling the class. Then, after compiling this class, just put it where the jdk can find it (so you don't have to change the CLASSPATH all the time) and run your NetBeans with the name of that LaF class of yours...
It's even easier because you don't have to remember sun's names all the time. packages…
Your com.example.laf.CustomTheme
versus sun'scom.sun.java.swing.plaf.motif.MotifLookAndFeel , for example...

L
Lubchak, 2014-02-22
@lubchak

And you can start using JavaFX and edit all css.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question