Changing the Look’n’Feel of VASSAL
In Swing library (the Java Graphical User Interface - GUI) look’n’feel denotes the way the various GUI elements present. There are various look’n’feel (or lnf
) available with a Java platform - some of them depending on who made the platform (yes, not all Java platforms are the same).
Name | Class |
---|---|
Metal | javax.swing.plaf.metal.MetalLookAndFeel |
Nimbus | javax.swing.plaf.nimbus.NimbusLookAndFeel |
CDE/Motif | com.sun.java.swing.plaf.motif.MotifLookAndFeel |
GTK+ | com.sun.java.swing.plaf.gtk.GTKLookAndFeel |
Windows | com.sun.java.swing.plaf.windows.WindowsLookAndFeel |
Windows Classic | com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel |
Mac OS X | com.apple.laf.AquaLookAndFeel |
The above table is in no way complete, and not all are available on all platforms.
Each Java platform defines a System
look’n’feel which typically defaults to a reasonable value. For example, it will default to GTK on Linux and Solaris if installed with GTK support. On Windows, it will default to Windows or Windows Classic depending on the version of the OS (newer or older than Vista). On MacOS, it will be Mac OS X. If the defaults cannot be found, then every platform will fall back to Metal.
Note, look’n’feel is not the same as theme. For example, the GTK and Windows look’n’feels will use the corresponding GTK and Windows theme, respectively, set by the user. Also, some of the look’n’feels allow per-application theme-ing via Java byte-compiled code, most notably the Metal look’n’feel.
The regular way of setting the Java look’n’feel
In most Java applications, one can change the look’n’feel by several methods. The setting is given by one of the class names given in the above table.
-
Setting the property
swing.defaultlaf
in$JAVA_HOME/conf/swing.properties
, for exampleswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel
-
Setting the property
swing.defaultlaf
on the command line:java -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel ...
-
In the application itself (see link above).
Demo
To see these look’n’feels in action download SwingSet2.jar
and run it like
java -jar SwingSet2.jar
Note:
-
For Windows users, assume you have VASSAL installed in
C:\Program Files\VASSAL
, doC:\Program Files\VASSAL\jre\bin\java.exe -jar SwingSet2.jar
-
For MacOSX users, assume you have VASSAL installed in
/Applications/VASSAL.app
, do/Applications/VASSAL.app/Contents/MacOS/jre/bin/java -jar SwingSet2.jar
-
For Linux users, just do the above command line.
(Click on the images to enlarge)
Setting the look’n’feel for VASSAL
VASSAL sets the look’n’feel to the system look’n’feel explicitly on non-Windows platforms (e.g., Linux and MacOSX). That means we cannot use either swing.properties
or the command -Dswing.defaultlaf
to set the look’n’feel on those two platforms.
Below are some samples of a module running in VASSAL (click image to enlarge).
On Windows
On Windows, VASSAL defaults to the Metal look’n’feel.
Since VASSAL ships with its own Java Virtual Machine (JVM), we should change the settings for that JVM. Suppose VASSAL is installed in C:\Program Files\VASSAL
, then the Java Runtime Environment (JRE) is installed in
C:\Program Files\VASSAL\jre
and we have to edit
C:\Program Files\VASSAL\jre\conf\swing.properties
to have content like
swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
or any other look’n’feel available (typically, Metal
, Nimbus
, Motif
, Windows
, and WindowsClassic
).
On MacOSX
Since VASSAL ships with its own Java Virtual Machine (JVM), we should change the settings for that JVM. However, since the VASSAL code explicitly sets the look’n’feel to be the system look’n’feel, we cannot simply specify a new swing.defaultlaf
.
However, we can set the property swing.systemlaf
to override the platform choice. But, we have to set it via the environment variable _JAVA_OPTIONS
. Suppose VASSAL is installed in /Applications/VASSAL.app
, then one can do for example
_JAVA_OPTIONS="-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel" \
/Application/VASSAL.app/Contents/MacOS/VASSAL.sh
See also below for how to set this more permanently.
On Linux
Since the VASSAL code explicitly sets the look’n’feel to be the system look’n’feel, we cannot simply specify a new swing.defaultlaf
. Instead, we must override the system look’n’feel via the environment variable _JAVA_OPTIONS
. Assuming VASSAL is installed in /opt/vassal/current
, then we could for example do
_JAVA_OPTIONS="-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel" \
/opt/vassal/current/VASSAL.sh
See also below for how to set this more permanently.
Setting _JAVA_OPTIONS
There are several ways to set _JAVA_OPTIONS
depending on your liking.
The first option is to set it in your shell configuration - e.g., ~/.profile
, by adding a line like
export _JAVA_OPTIONS="-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel"
to that file. This will, however, set the look’n’feel for all Java applications.
Another option, is to create an alias in the same file (~/.profile
) by adding a line like
alias vassal="_JAVA_OPTIONS=-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel /opt/vassal/current/VASSAL.sh"
again assuming /opt/vassal/current/VASSAL.sh
is the appropriate path (for MacOSX it will be something like /Application/VASSAL.app/Contents/MacOS/VASSAL.sh
).
Thirdly, you could generate a script in ~/.local/bin/vassal
with content like
#!/bin/sh
_JAVA_OPTIONS=-Dswing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel \
/opt/vassal/current/VASSAL.sh "$@"
again, with /opt/vassal/current/VASSAL.sh
assumed to be the installation.
Note, if you used these instructions to integrate VASSAL into your Linux desktop, then the script ~/.local/bin/vassal
has already been created and you can edit that. Note, to avoid overwriting your changes to that script, you can pass the option -W
to the integration.sh
script.
Custom Look’n’Feels
In principle, if one has a custom look’n’feel package - say mylaf.jar
with class mine.MyLaF
, one could do
_JAVA_OPTIONS="-classpath:/opt/vassal/current/lib/Vengine.jar:mylaf.jar -Dswing.systemlaf=mine.MyLaF" \
/opt/vassal/current/VASSAL.sh
to use the look’n’feel MyLaF
. However, under the hood VASSAL does some funny and does not pass everything on to child processes. Thus, the above will only effect the Launcher
- not the module windows.