Apply the EaSynth Look And Feel in Your Applications
Join the DZone community and get the full member experience.
Join For FreeEaSynth look and feel is a free and open-source Java look and feel provided by www.easynth.com. It is based on the Synth look and feel supported by JRE5+. The new look and feel provides a bronze-coloured theme, here is a snapshot:
We can download the EaSynth look and feel at:
http://www.easynth.com/freewares/EaSynthLAF/download/EaSynth_Look_And_Feel_Bundle.zip
It is a full bundle that contains the whole look and feel and its source code. We don't need the source code for usage purpose, so we extract the "EaSynthLookAndFeel.jar" file from the ZIP package, the JAR file is fairly enough for using EaSynth look and feel.
The first step to apply the new look and feel is appending the look and feel JAR file into the classpath, which is very simple:
java -cp EaSynthLookAndFeel.jar com.yourdomain.SampleMainClass
The second step is to specify the current look and feel; it can be achieved by using the swing.defaultlaf VM arguments:
java -Dswing.defaultlaf=com.easynth.lookandfeel.EaSynthLookAndFeel -cp EaSynthLookAndFeel.jar com.yourdomain.SampleMainClass
This will set the EaSynth look and feel as the default one. If you want to switch the look and feel on the fly, you can invoke the setLookAndFeel() static method in UIManager class:
Example 1: use the class name as the parameter for setLookAndFeel()
try {
UIManager.setLookAndFeel("com.easynth.lookandfeel.EaSynthLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
Example 2: use the look and feel object as the parameter for setLookAndFeel()
import com.easynth.lookandfeel.EaSynthLookAndFeel;
try {
final EaSynthLookAndFeel easynthLAF = new EaSynthLookAndFeel();
UIManager.setLookAndFeel(easynthLAF);
} catch (Exception e) {
e.printStackTrace();
}
The 2 examples above are equivalent on runtime, the second one may complain if the "EaSynthLookAndFeel.jar" file is not placed in the classpath. If you invoke setLookAndFeel() method at the first line of the main() method, it will work properly, all UI components will have the new style. But if you invoke setLookAndFeel() method latter (e.g. set new look and feel when user select a menu item), you may find that the UI components still keep their old style. To fix this, you need to invoke the updateComponentTreeUI() method to update the UI for all existing GUI components. Here is the example:
Example 3: update the UIs for the given GUI component and its children, and children's children... So that they will have the new looking.
SwingUtilities.updateComponentTreeUI(yourMainFrameInstance);
In most cases, applying EaSynth look and feel to your application will be very easy, and you don't need to modify any existing source code in your application. But if you specified some UI component's properties distinctly in the source code (such as the opaque property, table row height...), it may conflict with the default settings that comes from EaSynth look and feel. These kinds of issues can be fixed by performing some slight modification on the existing source code.
Opinions expressed by DZone contributors are their own.
Comments