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:net.sf.vntconverter.VntConverter.java

/**
 * Fhrt den VntConverter mit den angegebnen Optionen aus.
 *///from  w ww . j a va2 s .  co  m
public static void main(String[] args) {
    try {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            // Wenn nicht, dann nicht ...
        }
        JFileChooser fileChooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files (txt) and memo files (vnt)",
                "txt", "vnt");
        fileChooser.setCurrentDirectory(new java.io.File("."));
        fileChooser.setDialogTitle("Choose files to convert ...");
        fileChooser.setFileFilter(filter);
        fileChooser.setMultiSelectionEnabled(true);
        if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            JFileChooser directoryChooser = new JFileChooser();
            directoryChooser.setCurrentDirectory(new java.io.File("."));
            directoryChooser.setDialogTitle("Choose target directory ...");
            directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            directoryChooser.setAcceptAllFileFilterUsed(false);
            if (directoryChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                VntConverter converter = new VntConverter();
                String targetDirectoy = directoryChooser.getSelectedFile().getAbsolutePath();
                System.out.println(targetDirectoy);
                for (File file : fileChooser.getSelectedFiles()) {
                    if (file.getName().endsWith(".txt")) {
                        converter.encode(file,
                                new File(targetDirectoy + "\\" + file.getName().replace(".txt", ".vnt")));
                    } else if (file.getName().endsWith(".vnt")) {
                        converter.decode(file,
                                new File(targetDirectoy + "\\" + file.getName().replace(".vnt", ".txt")));
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception caught", e);
    }
}

From source file:EditorDropTarget2.java

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

    final JFrame f = new JFrame("JEditor Pane Drop Target Example 2");

    final JEditorPane pane = new JEditorPane();

    // Add a drop target to the JEditorPane
    EditorDropTarget2 target = new EditorDropTarget2(pane);

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();
    final JCheckBox editable = new JCheckBox("Editable");
    editable.setSelected(true);
    panel.add(editable);
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editable.isSelected());
        }
    });

    f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);
    f.getContentPane().add(panel, BorderLayout.SOUTH);
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:de.hstsoft.sdeep.view.MainWindow.java

public static void main(String[] args) {
    try {//  ww w  .jav a2  s . c  om
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            MainWindow mainWindow = new MainWindow();
            mainWindow.createUI();
            mainWindow.setSize(1024, 768);
            mainWindow.loadConfiguration();
            mainWindow.setVisible(true);
        }
    });

}

From source file:com.adito.server.Main.java

/**
 * Entry point//www.  j a v a 2 s  . c  o m
 * 
 * @param args
 * @throws Throwable
 */
public static void main(String[] args) throws Throwable {

    // This is a hack to allow the Install4J installer to get the java
    // runtime that will be used
    if (args.length > 0 && args[0].equals("--jvmdir")) {
        System.out.println(SystemProperties.get("java.home"));
        System.exit(0);
    }
    useWrapper = System.getProperty("wrapper.key") != null;
    final Main main = new Main();
    ContextHolder.setContext(main);

    if (useWrapper) {
        WrapperManager.start(main, args);
    } else {
        Integer returnCode = main.start(args);
        if (returnCode != null) {
            if (main.gui) {
                if (main.startupException == null) {
                    main.startupException = new Exception("An exit code of " + returnCode + " was returned.");
                }
                try {
                    if (SystemProperties.get("os.name").toLowerCase().startsWith("windows")) {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    }
                } catch (Exception e) {
                }
                String mesg = main.startupException.getMessage() == null ? "No message supplied."
                        : main.startupException.getMessage();
                StringBuffer buf = new StringBuffer();
                int l = 0;
                char ch = ' ';
                for (int i = 0; i < mesg.length(); i++) {
                    ch = mesg.charAt(i);
                    if (l > 50 && ch == ' ') {
                        buf.append("\n");
                        l = 0;
                    } else {
                        if (ch == '\n') {
                            l = 0;
                        } else {
                            l++;
                        }
                        buf.append(ch);
                    }
                }
                mesg = buf.toString();
                final String fMesg = mesg;
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(null, fMesg, "Startup Error", JOptionPane.ERROR_MESSAGE);
                    }
                });
            }
            System.exit(returnCode.intValue());
        } else {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    if (!main.shuttingDown) {
                        main.stop(0);
                    }
                }
            });
        }
    }
}

From source file:org.pegadi.client.ApplicationLauncher.java

public static void main(String[] args) {
    com.sun.net.ssl.internal.ssl.Provider provider = new com.sun.net.ssl.internal.ssl.Provider();
    java.security.Security.addProvider(provider);
    setAllPermissions();//from ww  w.  j a  v a2  s .  com
    /**
     * If we are on Apples operating system, we would like to use the screen
     * menu bar It is the first property we set in our main method. This is
     * to make sure that the property is set before awt is loaded.
     */
    if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
    }
    Logger log = LoggerFactory.getLogger(ApplicationLauncher.class);
    /**
     * Making sure default L&F is System
     */
    if (!UIManager.getLookAndFeel().getName().equals(UIManager.getSystemLookAndFeelClassName())) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.warn("Unable to change L&F to System", e);
        }
    }

    long start = System.currentTimeMillis();

    // Splash
    Splash splash = new Splash("/images/splash.png");
    splash.setVisible(true);

    splash.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "org/pegadi/client/client-context.xml");
    closeContextOnShutdown(context);

    long timeToLogin = System.currentTimeMillis() - start;
    log.info("Connected OK after {} ms", timeToLogin);
    log.info("Java Version {}", System.getProperty("java.version"));

    splash.dispose();
}

From source file:MonitorSaurausRex.MainMenu.java

/**
 * @param args the command line arguments
 *//*  w  w  w .  ja v  a  2s . com*/
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainMenu().setVisible(true);
        }
    });

    /* Use an appropriate Look and Feel */
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException
            | ClassNotFoundException ex) {
    }
    /* Turn off metal's use of bold fonts */
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    //Schedule a job for the event-dispatching thread:
    //adding TrayIcon.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java

public static void main(String[] args) {
    System.setProperty("awt.useSystemAAFontSettings", "on");
    System.setProperty("swing.aatext", "true");
    SwingUtilities.invokeLater(new Runnable() {

        @Override//from   w  w w . j  av  a  2s  . c o m
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                File tmpFolder = new File("/tmp/images");
                tmpFolder.mkdir();

                String coverPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/cover.jpg";
                String backdropPath = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/backdrop.jpg";
                String fanart1Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart1.jpg";
                String fanart2Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart2.jpg";
                String fanart3Path = tmpFolder.getAbsolutePath().replaceAll("\\\\", "/") + "/fanart3.jpg";

                PreviewJFrame frame = new PreviewJFrame();
                logger.info("Creating parser...");
                InfoRetriever parser = new MediaInfoRetriever();
                MovieInfo movieInfo = parser.getMovieInfo("/media/tagliani/Elements/Film/JackRyan.mkv");
                logger.info("Retrieving movie file info...");
                logger.info("Creating dataretriever...");
                DataRetriever retriever = new DataRetrieverImpl();
                logger.info("Retrieving movie data...");
                Movie movie = retriever.retrieveMovieFromImdbID("tt1205537", "IT");
                logger.info("Retrieving backdrops and fanart...");
                List<Artwork> images = movie.getBackdrops();
                // background
                logger.info("Saving backdrop...");
                IOUtils.copyLarge(new URL(images.get(0).getImageURL()).openStream(),
                        new FileOutputStream(backdropPath));
                for (int i = 1; i < 4; i++) {
                    // fanart1
                    // fanart2
                    // fanart3
                    String imageURL = images.get(i).getImageURL();
                    logger.info("Saving fanart{}...", i);
                    IOUtils.copyLarge(new URL(imageURL).openStream(),
                            new FileOutputStream(tmpFolder.getAbsolutePath() + "/fanart" + i + ".jpg"));
                }
                // cover
                logger.info("Retrieving cover...");
                Artwork cover = movie.getPosters().get(0);
                String imageURL = cover.getImageURL();
                logger.info("Saving cover...");
                IOUtils.copyLarge(new URL(imageURL).openStream(), new FileOutputStream(coverPath));

                Map<String, String> tokenMap = TemplateFilter.createTokenMap(movie, movieInfo, null);

                logger.info("Creating renderer...");
                JavaTemplateRenderer renderer = new JavaTemplateRenderer();
                JPanel imagePanel = null;
                try {
                    logger.info("Rendering image...");
                    imagePanel = renderer.renderTemplate(
                            this.getClass().getResource("/templates/simplicity/template.xml"), tokenMap,
                            backdropPath, fanart1Path, fanart2Path, fanart3Path, coverPath);
                    logger.info("Adding image to frame...");
                    frame.add(imagePanel);

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                imagePanel.setPreferredSize(new Dimension(imagePanel.getWidth(), imagePanel.getHeight()));
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.setVisible(true);
                frame.pack();
                logger.info("Creating image for save...");
                BufferedImage imageTosave = ScreenImage.createImage(imagePanel);
                logger.info("Saving image...");
                ScreenImage.writeImage(imageTosave, "/tmp/images/final.png");
                logger.info("Image saved...");
            } catch (Exception ex) {
                logger.error("Error: ", ex);
            }
        }

    });

}

From source file:EditorPaneExample10.java

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

    JFrame f = new EditorPaneExample10();

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:es.darkhogg.hazelnutt.Hazelnutt.java

/**
 * Runs the application//from  w ww . j  a va2 s.co  m
 * 
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    // Print some version information
    LOGGER.log(Level.OFF, "----------------");
    LOGGER.info("Hazelnutt " + VERSION);

    LOGGER.trace("Selecting Look&Feel...");

    // Select the L&F from configuration or the default if not present
    String slaf = CONFIG.getString("Hazelnutt.gui.lookAndFeel");
    if (slaf == null) {
        LOGGER.info("Configuration entry for L&F missing, creating default");
        slaf = UIManager.getSystemLookAndFeelClassName();
    }

    // Set it or print an error
    try {
        UIManager.setLookAndFeel(slaf);
    } catch (Exception e) {
        LOGGER.warn("Error while selecting the L&F \"" + slaf + "\", leaving default");
    }

    // Update the configuration with the currently selected L&F
    LookAndFeel laf = UIManager.getLookAndFeel();
    LOGGER.debug("L&F selected: " + laf.getName() + " (" + laf.getClass().getName() + ")");
    CONFIG.setProperty("Hazelnutt.gui.lookAndFeel", laf.getClass().getName());

    // Load the frame
    LOGGER.trace("Launching main frame...");
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            SwingUtilities.updateComponentTreeUI(FRAME);
            FRAME.setVisible(true);
        }
    });
}

From source file:edu.ku.brc.specify.config.init.SpecifyDBSetupWizardFrame.java

/**
 * @param args//from w ww  .j  a va  2 s.com
 */
public static void main(String[] args) {
    // Set App Name, MUST be done very first thing!
    UIRegistry.setAppName("Specify"); //$NON-NLS-1$

    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) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDBSetupWizard.class, e);
        e.printStackTrace();
    }

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

    System.setProperty("appdatadir", "..");

    // 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$

    // Load Local Prefs
    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    //try {
    //System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "+(new File(UIRegistry.getAppDataDir()).getCanonicalPath())+"]");
    //} catch (IOException ex) {}

    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    // Check to see if we should check for a new version
    if (localPrefs.getBoolean(VERSION_CHECK, null) == null) {
        localPrefs.putBoolean(VERSION_CHECK, true);
    }

    if (localPrefs.getBoolean(EXTRA_CHECK, null) == null) {
        localPrefs.putBoolean(EXTRA_CHECK, true);
    }

    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();
                }
            }
        });
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                startupContinuing();
            }
        });
    }
}