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:fr.eurecom.hybris.demogui.HybrisDemoGui.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                new HybrisDemoGui();
            } catch (Exception e) {
                e.printStackTrace();//from ww  w  .j  a v a2 s .co m
            }
        }
    });
}

From source file:misc.DesktopDemo.java

public static void main(String args[]) {
    /* Use an appropriate Look and Feel */
    try {/*ww  w. ja  v a 2s . c  o m*/
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (UnsupportedLookAndFeelException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
    /* Turn off metal's use of bold fonts */
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new DesktopDemo().setVisible(true);
        }
    });
}

From source file:at.co.malli.relpm.RelPM.java

/**
 * @param args the command line arguments
 *//* w  w  w .  j a  v a 2s .c  o  m*/
public static void main(String[] args) {
    //<editor-fold defaultstate="collapsed" desc=" Create config & log directory ">
    String userHome = System.getProperty("user.home");
    File relPm = new File(userHome + "/.RelPM");
    if (!relPm.exists()) {
        boolean worked = relPm.mkdir();
        if (!worked) {
            ExceptionDisplayer.showErrorMessage(new Exception("Could not create directory "
                    + relPm.getAbsolutePath() + " to store user-settings and logs"));
            System.exit(-1);
        }
    }
    File userConfig = new File(relPm.getAbsolutePath() + "/RelPM-userconfig.xml"); //should be created...
    if (!userConfig.exists()) {
        try {
            URL resource = RelPM.class.getResource("/at/co/malli/relpm/RelPM-defaults.xml");
            FileUtils.copyURLToFile(resource, userConfig);
        } catch (IOException ex) {
            ExceptionDisplayer.showErrorMessage(new Exception("Could not copy default config. Reason:\n"
                    + ex.getClass().getName() + ": " + ex.getMessage()));
            System.exit(-1);
        }
    }
    if (!userConfig.canWrite() || !userConfig.canRead()) {
        ExceptionDisplayer.showErrorMessage(new Exception(
                "Can not read or write " + userConfig.getAbsolutePath() + "to store user-settings"));
        System.exit(-1);
    }
    if (System.getProperty("os.name").toLowerCase().contains("win")) {
        Path relPmPath = Paths.get(relPm.toURI());
        try {
            Files.setAttribute(relPmPath, "dos:hidden", true);
        } catch (IOException ex) {
            ExceptionDisplayer.showErrorMessage(new Exception("Could not set " + relPm.getAbsolutePath()
                    + " hidden. " + "Reason:\n" + ex.getClass().getName() + ": " + ex.getMessage()));
            System.exit(-1);
        }
    }
    //</editor-fold>

    logger.trace("Environment setup sucessfull");

    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code ">
    try {
        String wantedLookAndFeel = SettingsProvider.getInstance().getString("gui.lookAndFeel");
        UIManager.LookAndFeelInfo[] installed = UIManager.getInstalledLookAndFeels();
        boolean found = false;
        for (UIManager.LookAndFeelInfo info : installed) {
            if (info.getClassName().equals(wantedLookAndFeel))
                found = true;
        }
        if (found)
            UIManager.setLookAndFeel(wantedLookAndFeel);
        else
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    } catch (InstantiationException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    } catch (IllegalAccessException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Add GUI start to awt EventQue ">
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainGUI().setVisible(true);
        }
    });
    //</editor-fold>
}

From source file:com.antelink.sourcesquare.SourceSquare.java

public static void main(String[] args) {

    logger.debug("starting.....");

    final EventBus eventBus = new EventBus();

    AntepediaQuery query = new AntepediaQuery();

    SourceSquareEngine engine = new SourceSquareEngine(eventBus, query);

    ScanStatusManager manager = new ScanStatusManager(eventBus);
    manager.bind();//from w ww.jav a2s  .co  m

    TreeMapBuilder treemap = new TreeMapBuilder(eventBus);
    treemap.bind();

    ResultBuilder builder = new ResultBuilder(eventBus, treemap);
    builder.bind();

    final SourceSquareFSWalker walker = new SourceSquareFSWalker(engine, eventBus, treemap);
    walker.bind();

    ServerController.bind(eventBus);
    if (args.length != 0) {
        final File toScan = new File(args[0]);

        if (!toScan.isDirectory()) {
            logger.error("The argument is not a directory");
            logger.info("exiting SourceSquare");
            System.exit(0);
        }

        eventBus.fireEvent(new StartScanEvent(toScan));

        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "SourceSquare");

        logger.info("Scan complete");
        logger.info("Number of files to scan: " + ScanStatus.INSTANCE.getNbFilesToScan());
        logger.info("Number of files Scanned: " + ScanStatus.INSTANCE.getNbFilesScanned());
        logger.info("Number of files open source: " + ScanStatus.INSTANCE.getNbOSFilesFound());
    } else {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            logger.info("Error launching the UI", e);
        } catch (InstantiationException e) {
            logger.info("Error launching the UI", e);
        } catch (IllegalAccessException e) {
            logger.info("Error launching the UI", e);
        } catch (UnsupportedLookAndFeelException e) {
            logger.info("Error launching the UI", e);
        }
        SourceSquareView view = new SourceSquareView();
        SourceSquareController controller = new SourceSquareController(view, eventBus);

        ExitSourceSquareView exitView = new ExitSourceSquareView();
        ExitController exitController = new ExitController(exitView, eventBus);

        exitController.bind();
        controller.bind();
        controller.display();
    }

}

From source file:fll.subjective.SubjectiveFrame.java

public static void main(final String[] args) {
    LogUtils.initializeLogging();/*  www .j  a  v a  2  s  . c  om*/

    Thread.setDefaultUncaughtExceptionHandler(new GuiExceptionHandler());

    // Use cross platform look and feel so that things look right all of the
    // time
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (final ClassNotFoundException e) {
        LOGGER.warn("Could not find cross platform look and feel class", e);
    } catch (final InstantiationException e) {
        LOGGER.warn("Could not instantiate cross platform look and feel class", e);
    } catch (final IllegalAccessException e) {
        LOGGER.warn("Error loading cross platform look and feel", e);
    } catch (final UnsupportedLookAndFeelException e) {
        LOGGER.warn("Cross platform look and feel unsupported?", e);
    }

    try {
        final SubjectiveFrame frame = new SubjectiveFrame();
        frame.addWindowListener(new WindowAdapter() {
            @Override
            @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK")
            public void windowClosing(final WindowEvent e) {
                System.exit(0);
            }

            @Override
            @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK")
            public void windowClosed(final WindowEvent e) {
                System.exit(0);
            }
        });
        // should be able to watch for window closing, but hidden works
        frame.addComponentListener(new ComponentAdapter() {
            @Override
            @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK")
            public void componentHidden(final ComponentEvent e) {
                System.exit(0);
            }
        });
        GraphicsUtils.centerWindow(frame);
        frame.setVisible(true);
        frame.promptForFile();

    } catch (final Throwable e) {
        JOptionPane.showMessageDialog(null, "Unexpected error: " + e.getMessage(), "Error",
                JOptionPane.ERROR_MESSAGE);
        LOGGER.fatal("Unexpected error", e);
        System.exit(1);
    }
}

From source file:UndoExample3.java

public static void main(String[] args) {
    try {//w w w .  j av a  2  s.  co  m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new UndoExample3();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:UndoExample4.java

public static void main(String[] args) {
    try {/*from   ww w  .  j a  v a 2s  .com*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new UndoExample4();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:eu.mrbussy.pdfsplitter.Application.java

/**
 * Start the main program.//www.j a  va2s.  co  m
 * 
 * @param args
 *            - Arguments passed on to the program
 */
public static void main(String[] args) {

    // Read configurations
    try {
        String configDirname = FilenameUtils.concat(System.getProperty("user.home"),
                String.format(".%1$s%2$s", NAME, IOUtils.DIR_SEPARATOR));
        String filename = FilenameUtils.concat(configDirname, CONFIGURATION_FILE);

        // Check to see if the directory exists and the file can be created/opened
        File configDir = new File(configDirname);
        if (!configDir.exists())
            configDir.mkdir();

        // Check to see if the file exists. If not create it
        File file = new File(filename);
        if (!file.exists()) {
            file.createNewFile();
        }
        Configuration = new PropertiesConfiguration(file);
        // Automatically store the settings that change
        Configuration.setAutoSave(true);

    } catch (ConfigurationException | IOException ex) {
        // Unable to read the file. Probably because it does not exist --> create it.
        ex.printStackTrace();
    }

    // Set locale to a configured language
    Locale.setDefault(
            new Locale(Configuration.getString("language", "nl"), Configuration.getString("country", "NL")));

    // Start by parsing the command line
    ParseCommandline(args);

    // Display the help if required and leave the app
    if (arguments.hasOption("h")) {
        showHelp();
    }

    // Display the app version and leave the app.
    if (arguments.hasOption("v")) {
        showVersion();
    }

    // Not command line so start the app GUI
    if (!arguments.hasOption("c")) {
        try {
            // Change the look and feel
            UIManager.setLookAndFeel(
                    Configuration.getString("LookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    (new MainWindow()).setVisible(true);
                }
            });
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            // Something terrible happened so show the  help
            showHelp();
        }

    }

}

From source file:CelsiusConverter.java

public static void main(String[] args) {
    // Set the look and feel.
    try {/* w  w w.java  2  s.com*/
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
    }

    CelsiusConverter converter = new CelsiusConverter();
}

From source file:net.openbyte.Launch.java

/**
 * This is the main method that allows Java to initiate the program.
 *
 * @param args the arguments to the Java program, which are ignored
 */// w  w w .j  ava  2s. com
public static void main(String[] args) {
    logger.info("Checking for a new version...");
    try {
        GitHub gitHub = new GitHubBuilder().withOAuthToken("e5b60cea047a3e44d4fc83adb86ea35bda131744 ").build();
        GHRepository repository = gitHub.getUser("PizzaCrust").getRepository("OpenByte");
        for (GHRelease release : repository.listReleases()) {
            double releaseTag = Double.parseDouble(release.getTagName());
            if (CURRENT_VERSION < releaseTag) {
                logger.info("Version " + releaseTag + " has been released.");
                JOptionPane.showMessageDialog(null,
                        "Please update OpenByte to " + releaseTag
                                + " at https://github.com/PizzaCrust/OpenByte.",
                        "Update", JOptionPane.WARNING_MESSAGE);
            } else {
                logger.info("OpenByte is at the latest version.");
            }
        }
    } catch (Exception e) {
        logger.error("Failed to connect to GitHub.");
        e.printStackTrace();
    }
    logger.info("Checking for a workspace folder...");
    if (!Files.WORKSPACE_DIRECTORY.exists()) {
        logger.info("Workspace directory not found, creating one.");
        Files.WORKSPACE_DIRECTORY.mkdir();
    }
    logger.info("Checking for a plugins folder...");
    if (!Files.PLUGINS_DIRECTORY.exists()) {
        logger.info("Plugins directory not found, creating one.");
        Files.PLUGINS_DIRECTORY.mkdir();
    }
    try {
        logger.info("Grabbing and applying system look and feel...");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException e) {
        logger.info("Something went wrong when applying the look and feel, using the default one...");
        e.printStackTrace();
    }
    logger.info("Starting event manager...");
    EventManager.init();
    logger.info("Detecting plugin files...");
    File[] pluginFiles = PluginManager.getPluginFiles(Files.PLUGINS_DIRECTORY);
    logger.info("Detected " + pluginFiles.length + " plugin files in the plugins directory!");
    logger.info("Beginning load/register plugin process...");
    for (File pluginFile : pluginFiles) {
        logger.info("Loading file " + FilenameUtils.removeExtension(pluginFile.getName()) + "...");
        try {
            PluginManager.registerAndLoadPlugin(pluginFile);
        } catch (Exception e) {
            logger.error("Failed to load file " + FilenameUtils.removeExtension(pluginFile.getName()) + "!");
            e.printStackTrace();
        }
    }
    logger.info("All plugin files were loaded/registered to OpenByte.");
    logger.info("Showing graphical interface to user...");
    WelcomeFrame welcomeFrame = new WelcomeFrame();
    welcomeFrame.setVisible(true);
}