Java Swing Look and Feel getSortedInstalledLAFInfos()

Here you can find the source of getSortedInstalledLAFInfos()

Description

Returns the installed LAF info array sorted by my preference.

License

Apache License

Return

the installed LAF info array sorted by my preference

Declaration

public static LookAndFeelInfo[] getSortedInstalledLAFInfos() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.Comparator;

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

public class Main {
    /**//from w  w w .jav a 2 s.c  om
     * Returns the installed LAF info array sorted by my preference.
     * @return the installed LAF info array sorted by my preference
     */
    public static LookAndFeelInfo[] getSortedInstalledLAFInfos() {
        final LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();

        Arrays.sort(installedLookAndFeels, new Comparator<LookAndFeelInfo>() {
            // What we want to prioritize:
            final String[] lafNamesInOrder = new String[] { "Nimbus", "Metal", "Windows", "Squareness",
                    "Office 2003", "Office XP", "Visual Studio 2005" };

            @Override
            public int compare(final LookAndFeelInfo l1, final LookAndFeelInfo l2) {
                for (final String lafName : lafNamesInOrder) {
                    if (lafName.equals(l1.getName()))
                        return -1;
                    if (lafName.equals(l2.getName()))
                        return 1;
                }

                return 0; // The rest is good as is.
            }
        });

        return installedLookAndFeels;
    }
}

Related

  1. getLookAndFeel(final String displayName)
  2. getLookAndFeel(String name)
  3. getLookAndFeelInfo()
  4. getLookAndFeelToSave()
  5. getNimbusLAF()
  6. getSysDefLookandFeel()
  7. getSystemLAF()
  8. initLookAndFeel()
  9. initLookAndFeel()