Java Utililty Methods Swing Look and Feel

List of utility methods to do Swing Look and Feel

Description

The list of methods to do Swing Look and Feel are organized into topic(s).

Method

voidsetLookAndFeel(Component comp, LookAndFeel lf)
set Look And Feel
try {
    UIManager.setLookAndFeel(lf);
    SwingUtilities.updateComponentTreeUI(comp);
} catch (Exception e) {
    e.printStackTrace(System.err);
voidsetLookAndFeel(final Class lookAndFeel)
Sets the entire L&F based on "simple" name.
if (lookAndFeel == null) {
    setLookAndFeelByName(null);
} else {
    setLookAndFeelByName(lookAndFeel.getName());
voidsetLookAndFeel(String laf)
set Look And Feel
try {
    UIManager.setLookAndFeel(laf);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
    e.printStackTrace();
voidsetLookAndFeel(String lafName)
set Look And Feel
for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
    if (lafName.equals(laf.getName())) {
        UIManager.setLookAndFeel(laf.getClassName());
voidsetLookAndFeel(String look)
Sets look and feel.
try {
    UIManager.setLookAndFeel(look);
} catch (ClassNotFoundException e) {
    throw new IllegalArgumentException("Class " + look + " is not found", e);
} catch (InstantiationException e) {
    throw new IllegalArgumentException("Instantiation problem when setting look and feel", e);
} catch (IllegalAccessException e) {
    throw new IllegalArgumentException("Security problem when setting look and feel", e);
...
booleansetLookAndFeel(String lookAndFeelClass)
set Look And Feel
try {
    UIManager.setLookAndFeel(lookAndFeelClass);
    return true;
} catch (Throwable t) {
    System.err.println(t.getMessage());
    return false;
voidsetLookAndFeelByName(final String lookAndFeel)
Sets the entire L&F based on "simple" name.
if (lookAndFeel == null) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    return;
String specified = lookAndFeel.toLowerCase(Locale.US).trim();
String current = UIManager.getLookAndFeel().getName().toLowerCase(Locale.US);
if (!specified.equals(current)) {
    try {
        for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            String name = info.getName().toLowerCase(Locale.US);
            String className = info.getClassName().toLowerCase(Locale.US);
            if (specified.equals(name) || specified.equals(className)) {
                UIManager.setLookAndFeel(info.getClassName());
                return;
    } catch (Exception e) {
        e.printStackTrace();
new Exception("Could not load " + lookAndFeel + ", it was not available.").printStackTrace();
voidsetLookAndTheme(LookAndFeel laf, Object theme)
set Look And Theme
UIManager.setLookAndFeel(laf);
voidsetMetalLAF()
Attempts to set the default look-and-feel to Metal.
setLAF(METAL_LAF_CLASS);
voidsetMotifLookAndFeel()
set Motif Look And Feel
try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (Exception e) {
    System.out.println("Error setting Motif LAF: " + e);