Example usage for javax.swing UIManager setLookAndFeel

List of usage examples for javax.swing UIManager setLookAndFeel

Introduction

In this page you can find the example usage for javax.swing UIManager setLookAndFeel.

Prototype

@SuppressWarnings("deprecation")
public static void setLookAndFeel(String className) throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, UnsupportedLookAndFeelException 

Source Link

Document

Loads the LookAndFeel specified by the given class name, using the current thread's context class loader, and passes it to setLookAndFeel(LookAndFeel) .

Usage

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

@SuppressWarnings("unchecked")
protected void changeLookAndFeel() {
    final JDialog dialog = new JDialog(mainFrame, "Design ndern");
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    Collection<TwoObjectsX<String, String>> lookAndFeels = FunctionsX.asList(
            new TwoObjectsX<String, String>("Metal", UIManager.getCrossPlatformLookAndFeelClassName()),
            new TwoObjectsX<String, String>("Betriebssystem Standard",
                    UIManager.getSystemLookAndFeelClassName()),
            new TwoObjectsX<String, String>("Nimbus", NimbusLookAndFeel.class.getName()));

    dialog.setLayout(new GridLayout(0, 1));
    ButtonGroup b = new ButtonGroup();
    for (final TwoObjectsX<String, String> lookAndFeel : lookAndFeels) {
        JRadioButton rb = new JRadioButton(lookAndFeel.getObjectA());
        if (iliasProperties.getLookAndFeel().equals(lookAndFeel.getObjectB())) {
            rb.setSelected(true);/*from   w  ww .j av a2 s. c  om*/
        }
        rb.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(lookAndFeel.getObjectB());
                    iliasProperties.setLookAndFeel(lookAndFeel.getObjectB());
                    saveProperties(iliasProperties);
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                        | UnsupportedLookAndFeelException e1) {
                    showError("Fehler beim ndern des Designs", e1);
                }
                SwingUtilities.updateComponentTreeUI(mainFrame);
                SwingUtilities.updateComponentTreeUI(dialog);

            }
        });
        b.add(rb);
        dialog.add(rb);
    }

    dialog.pack();
    dialog.setLocationRelativeTo(mainFrame);
    dialog.setVisible(true);

}

From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java

/**
  * @param args/*from w  ww.j ava  2  s  .c o  m*/
  */
public static void main(String[] args) {
    setAppName("Specify"); //$NON-NLS-1$
    System.setProperty(AppPreferences.factoryName, "edu.ku.brc.specify.config.AppPrefsDBIOIImpl"); // Needed by AppReferences //$NON-NLS-1$

    for (String s : args) {
        String[] pairs = s.split("="); //$NON-NLS-1$
        if (pairs.length == 2) {
            if (pairs[0].startsWith("-D")) //$NON-NLS-1$
            {
                //System.err.println("["+pairs[0].substring(2, pairs[0].length())+"]["+pairs[1]+"]");
                System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]);
            }
        } else {
            String symbol = pairs[0].substring(2, pairs[0].length());
            //System.err.println("["+symbol+"]");
            System.setProperty(symbol, symbol);
        }
    }

    // Now check the System Properties
    String appDir = System.getProperty("appdir");
    if (StringUtils.isNotEmpty(appDir)) {
        UIRegistry.setDefaultWorkingPath(appDir);
    }

    String appdatadir = System.getProperty("appdatadir");
    if (StringUtils.isNotEmpty(appdatadir)) {
        UIRegistry.setBaseAppDataDir(appdatadir);
    }

    // Then set this
    IconManager.setApplicationClass(Specify.class);
    IconManager.loadIcons(XMLHelper.getConfigDir("icons.xml")); //$NON-NLS-1$
    //ImageIcon icon = IconManager.getIcon("AppIcon", IconManager.IconSize.Std16);

    try {
        ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

    } catch (MissingResourceException ex) {
        Locale.setDefault(Locale.ENGLISH);
        UIRegistry.setResourceLocale(Locale.ENGLISH);
    }

    try {
        if (!System.getProperty("os.name").equals("Mac OS X")) {
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            PlasticLookAndFeel.setPlasticTheme(new DesertBlue());
        }
    } catch (Exception e) {
        //whatever
    }
    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    boolean doIt = false;
    if (doIt)

    {
        Charset utf8charset = Charset.forName("UTF-8");
        Charset iso88591charset = Charset.forName("ISO-8859-1");

        ByteBuffer inputBuffer = ByteBuffer.wrap(new byte[] { (byte) 0xC3, (byte) 0xA2 });

        // decode UTF-8
        CharBuffer data = utf8charset.decode(inputBuffer);

        // encode ISO-8559-1
        ByteBuffer outputBuffer = iso88591charset.encode(data);
        byte[] outputData = outputBuffer.array();
        System.out.println(new String(outputData));
        return;
    }

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIHelper.OSTYPE osType = UIHelper.getOSType();
                if (osType == UIHelper.OSTYPE.Windows) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

                } else if (osType == UIHelper.OSTYPE.Linux) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                }
            } catch (Exception e) {
                log.error("Can't change L&F: ", e); //$NON-NLS-1$
            }

            JFrame frame = new JFrame(getResourceString("StrLocalizerApp.AppTitle"));
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            final StrLocalizerApp sl = new StrLocalizerApp();
            sl.addMenuBar(frame);
            frame.setContentPane(sl);
            frame.setSize(768, 1024);

            //Dimension size = frame.getPreferredSize();
            //size.height = 500;
            //frame.setSize(size);
            frame.addWindowListener(sl);
            IconManager.setApplicationClass(Specify.class);
            frame.setIconImage(IconManager.getImage(IconManager.makeIconName("SpecifyWhite32")).getImage());
            UIHelper.centerAndShow(frame);

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    sl.startUp();
                }
            });
        }
    });
}

From source file:de.nmichael.efa.Daten.java

public static void iniGUI() {
    if (Logger.isTraceOn(Logger.TT_CORE, 9) || Logger.isDebugLoggingActivatedByCommandLine()) {
        Logger.log(Logger.DEBUG, Logger.MSG_CORE_STARTUPINITIALIZATION, "iniGUI()");
    }/*from w  w w.ja  v  a  2 s. c om*/
    if (!isGuiAppl()) {
        return;
    }
    iniScreenSize();

    // Look&Feel
    if (Daten.efaConfig != null) { // is null for applDRV
        try {
            if (Daten.efaConfig.getValueLookAndFeel().length() == 0) {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } else {
                UIManager.setLookAndFeel(Daten.efaConfig.getValueLookAndFeel());
            }
        } catch (Exception e) {
            Logger.log(Logger.WARNING, Logger.MSG_WARN_CANTSETLOOKANDFEEL,
                    International.getString("Konnte Look&Feel nicht setzen") + ": " + e.toString());
        }
    }

    // Look&Feel specific Work-Arounds
    try {
        lookAndFeel = UIManager.getLookAndFeel().getClass().toString();
        if (!lookAndFeel.endsWith("MetalLookAndFeel")) {
            // to make PopupMenu's work properly and not swallow the next MousePressed Event, see:
            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6753637
            Dialog.getUiDefaults().put("PopupMenu.consumeEventOnClose", false);
        }
        Color buttonFocusColor = (Daten.efaConfig != null ? Daten.efaConfig.getLafButtonFocusColor() : null);
        if (buttonFocusColor != null) {
            // colored square around text of selected button
            Dialog.getUiDefaults().put("Button.focus", new ColorUIResource(buttonFocusColor));
        }
        // allow users to press buttons by hitting ENTER (and not just SPACE)
        Dialog.getUiDefaults().put("Button.focusInputMap",
                new javax.swing.UIDefaults.LazyInputMap(new Object[] { "ENTER", "pressed", "released ENTER",
                        "released", "SPACE", "pressed", "released SPACE", "released" }));
    } catch (Exception e) {
        Logger.log(Logger.WARNING, Logger.MSG_WARN_CANTSETLOOKANDFEEL,
                "Failed to apply LookAndFeel Workarounds: " + e.toString());
    }

    // Font Size
    if (applID == APPL_EFABH) {
        try {
            Dialog.setGlobalFontSize(Daten.efaConfig.getValueEfaDirekt_fontSize(),
                    Daten.efaConfig.getValueEfaDirekt_fontStyle());
        } catch (Exception e) {
            Logger.log(Logger.WARNING, Logger.MSG_WARN_CANTSETFONTSIZE,
                    International.getString("Schriftgre konnte nicht gendert werden") + ": "
                            + e.toString());
        }
    }
}

From source file:ffx.ui.MainPanel.java

/**
 * <p>/*from   w  w w.  j a  v a2  s.  c  om*/
 * oceanLookAndFeel</p>
 */
public void oceanLookAndFeel() {
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        SwingUtilities.updateComponentTreeUI(SwingUtilities.getRoot(this));
    } catch (Exception e) {
        return;
    }
}

From source file:iad_zad3.gui.MainWindow.java

private static void initLookAndFeel() {
    String lookAndFeel = null;/* www .j  av  a  2s .c om*/
    lookAndFeel = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(lookAndFeel);
    } catch (ClassNotFoundException | UnsupportedLookAndFeelException e) {
    } catch (Exception e) {
        //TODO :)
    }
}

From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java

/**
 * @param args//from www. j  ava2 s .  c om
 */
public static void main(String[] args) {
    log.debug("********* Current [" + (new File(".").getAbsolutePath()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    // This is for Windows and Exe4J, turn the args into System Properties

    // Set App Name, MUST be done very first thing!
    //UIRegistry.setAppName("iReports4Specify");  //$NON-NLS-1$
    UIRegistry.setAppName("Specify"); //$NON-NLS-1$
    UIRegistry.setEmbeddedDBPath(UIRegistry.getDefaultEmbeddedDBPath()); // on the local machine

    AppBase.processArgs(args);
    AppBase.setupTeeForStdErrStdOut(true, false);

    // Then set this
    IconManager.setApplicationClass(Specify.class);
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$
    IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$

    Specify.setUpSystemProperties();

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());
    adjustLocaleFromPrefs();
    HibernateUtil.setListener("post-commit-update", new edu.ku.brc.specify.dbsupport.PostUpdateEventListener()); //$NON-NLS-1$
    HibernateUtil.setListener("post-commit-insert", new edu.ku.brc.specify.dbsupport.PostInsertEventListener()); //$NON-NLS-1$
    HibernateUtil.setListener("post-commit-delete", new edu.ku.brc.specify.dbsupport.PostDeleteEventListener()); //$NON-NLS-1$

    ImageIcon helpIcon = IconManager.getIcon(IconManager.makeIconName("AppIcon"), IconSize.Std16); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    try {
        UIHelper.OSTYPE osType = UIHelper.getOSType();
        if (osType == UIHelper.OSTYPE.Windows) {
            UIManager.setLookAndFeel(new PlasticLookAndFeel());
            PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

        } else if (osType == UIHelper.OSTYPE.Linux) {
            UIManager.setLookAndFeel(new PlasticLookAndFeel());
        }
    } catch (Exception e) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MainFrameSpecify.class, e);
        log.error("Can't change L&F: ", e); //$NON-NLS-1$
    }

    if (UIHelper.isLinux()) {
        Specify.checkForSpecifyAppsRunning();
    }

    if (UIRegistry.isEmbedded()) {
        ProcessListUtil.checkForMySQLProcesses(new ProcessListener() {
            @Override
            public void done(PROC_STATUS status) // called on the UI thread
            {
                if (status == PROC_STATUS.eOK || status == PROC_STATUS.eFoundAndKilled) {
                    startupContinuing(); // On UI Thread
                }
            }
        });
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                startupContinuing();
            }
        });
    }
}

From source file:Installer.java

public static void main(String[] args) {
    try {/*www  .  ja v  a2s.co m*/
        // Set System L&F
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    try {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:base.BasePlayer.AddGenome.java

public static void main(String[] args) {

    try {//from   w  w  w  .j a v a  2  s  . co  m

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    } catch (Exception e) {
        e.printStackTrace();
    }
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:ECallCenter21.java

private void setLookAndFeel(int plafIndexParam) {
    plafSelected = plaf[plafIndexParam];
    try {/*from   www .  j  a  v a2s.c o  m*/
        UIManager.setLookAndFeel(plafSelected);
    } catch (ClassNotFoundException ex) {
    } catch (InstantiationException ex) {
    } catch (IllegalAccessException ex) {
    } catch (UnsupportedLookAndFeelException ex) {
    }
    setVisible(false);
    setVisible(true);
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

/**
 * @param args the command line arguments
 *///from www. j a  v  a 2 s.com
public static void main(String args[]) {
    Logger.getRootLogger().addAppender(
            new ConsoleAppender(new org.apache.log4j.PatternLayout("%d - %-5p - %-20c (%C [%L]) - %m%n")));
    GlobalOptions.setSelectedServer("de43");
    GlobalOptions.setSelectedProfile(new DummyProfile());
    DataHolder.getSingleton().loadData(false);
    try {
        //  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (Exception e) {
    }

    DSWorkbenchReTimerFrame.getSingleton().resetView();
    DSWorkbenchReTimerFrame.getSingleton().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DSWorkbenchReTimerFrame.getSingleton().setVisible(true);
}