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.jsignpdf.Signer.java

/**
 * Main.//  ww w. j a v  a 2  s  . c o  m
 * 
 * @param args
 */
public static void main(String[] args) {
    SignerOptionsFromCmdLine tmpOpts = null;

    if (args != null && args.length > 0) {
        tmpOpts = new SignerOptionsFromCmdLine();
        parseCommandLine(args, tmpOpts);
    }

    try {
        SSLInitializer.init();
    } catch (Exception e) {
        LOGGER.warn("Unable to re-configure SSL layer", e);
    }

    pkcs11ProviderName = PKCS11Utils
            .registerProvider(ConfigProvider.getInstance().getProperty("pkcs11config.path"));

    traceInfo();

    if (tmpOpts != null) {
        if (tmpOpts.isPrintVersion()) {
            System.out.println("JSignPdf version " + VERSION);
        }
        if (tmpOpts.isPrintHelp()) {
            printHelp();
        }
        if (tmpOpts.isListKeyStores()) {
            LOGGER.info(RES.get("console.keystores"));
            for (String tmpKsType : KeyStoreUtils.getKeyStores()) {
                System.out.println(tmpKsType);
            }
        }
        if (tmpOpts.isListKeys()) {
            final String[] tmpKeyAliases = KeyStoreUtils.getKeyAliases(tmpOpts);
            LOGGER.info(RES.get("console.keys"));
            // list certificate aliases in the keystore
            for (String tmpCert : tmpKeyAliases) {
                System.out.println(tmpCert);
            }
        }
        if (ArrayUtils.isNotEmpty(tmpOpts.getFiles())
                || (!StringUtils.isEmpty(tmpOpts.getInFile()) && !StringUtils.isEmpty(tmpOpts.getOutFile()))) {
            signFiles(tmpOpts);
        } else {
            final boolean tmpCommand = tmpOpts.isPrintVersion() || tmpOpts.isPrintHelp()
                    || tmpOpts.isListKeyStores() || tmpOpts.isListKeys();
            if (!tmpCommand) {
                // no valid command provided - print help and exit
                printHelp();
                exit(EXIT_CODE_NO_COMMAND);
            }
        }
        exit(0);
    } else {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            System.err.println("Can't set Look&Feel.");
        }
        SignPdfForm tmpForm = new SignPdfForm(WindowConstants.EXIT_ON_CLOSE);
        tmpForm.pack();
        GuiUtils.center(tmpForm);
        tmpForm.setVisible(true);
    }
}

From source file:au.com.jwatmuff.eventmanager.Main.java

/**
 * Main method.//from   ww  w  . j  a v  a 2 s .  c  o  m
 */
public static void main(String args[]) {
    LogUtils.setupUncaughtExceptionHandler();

    /* Set timeout for RMI connections - TODO: move to external file */
    System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000");
    updateRmiHostName();

    /*
     * Set up menu bar for Mac
     */
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Event Manager");

    /*
     * Set look and feel to 'system' style
     */
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        log.info("Failed to set system look and feel");
    }

    /*
     * Set workingDir to a writable folder for storing competitions, settings etc.
     */
    String applicationData = System.getenv("APPDATA");
    if (applicationData != null) {
        workingDir = new File(applicationData, "EventManager");
        if (workingDir.exists() || workingDir.mkdirs()) {
            // redirect logging to writable folder
            LogUtils.reconfigureFileAppenders("log4j.properties", workingDir);
        } else {
            workingDir = new File(".");
        }
    }

    // log version for debugging
    log.info("Running version: " + VISIBLE_VERSION + " (Internal: " + VERSION + ")");

    /*
     * Copy license if necessary
     */
    File license1 = new File("license.lic");
    File license2 = new File(workingDir, "license.lic");
    if (license1.exists() && !license2.exists()) {
        try {
            FileUtils.copyFile(license1, license2);
        } catch (IOException e) {
            log.warn("Failed to copy license from " + license1 + " to " + license2, e);
        }
    }
    if (license1.exists() && license2.exists()) {
        if (license1.lastModified() > license2.lastModified()) {
            try {
                FileUtils.copyFile(license1, license2);
            } catch (IOException e) {
                log.warn("Failed to copy license from " + license1 + " to " + license2, e);
            }
        }
    }

    /*
     * Check if run lock exists, if so ask user if it is ok to continue
     */
    if (!obtainRunLock(false)) {
        int response = JOptionPane.showConfirmDialog(null,
                "Unable to obtain run-lock.\nPlease ensure that no other instances of EventManager are running before continuing.\nDo you wish to continue?",
                "Run-lock detected", JOptionPane.YES_NO_OPTION);
        if (response == JOptionPane.YES_OPTION)
            obtainRunLock(true);
        else
            System.exit(0);
    }

    try {
        LoadWindow loadWindow = new LoadWindow();
        loadWindow.setVisible(true);

        loadWindow.addMessage("Reading settings..");

        /*
         * Read properties from file
         */
        final Properties props = new Properties();
        try {
            Properties defaultProps = PropertiesLoaderUtils
                    .loadProperties(new ClassPathResource("eventmanager.properties"));
            props.putAll(defaultProps);
        } catch (IOException ex) {
            log.error(ex);
        }

        props.putAll(System.getProperties());

        File databaseStore = new File(workingDir, "comps");
        int rmiPort = Integer.parseInt(props.getProperty("eventmanager.rmi.port"));

        loadWindow.addMessage("Loading Peer Manager..");
        log.info("Loading Peer Manager");

        ManualDiscoveryService manualDiscoveryService = new ManualDiscoveryService();
        JmDNSRMIPeerManager peerManager = new JmDNSRMIPeerManager(rmiPort, new File(workingDir, "peerid.dat"));
        peerManager.addDiscoveryService(manualDiscoveryService);

        monitorNetworkInterfaceChanges(peerManager);

        loadWindow.addMessage("Loading Database Manager..");
        log.info("Loading Database Manager");

        DatabaseManager databaseManager = new SQLiteDatabaseManager(databaseStore, peerManager);
        LicenseManager licenseManager = new LicenseManager(workingDir);

        loadWindow.addMessage("Loading Load Competition Dialog..");
        log.info("Loading Load Competition Dialog");

        LoadCompetitionWindow loadCompetitionWindow = new LoadCompetitionWindow(databaseManager, licenseManager,
                peerManager);
        loadCompetitionWindow.setTitle(WINDOW_TITLE);

        loadWindow.dispose();
        log.info("Starting Load Competition Dialog");

        while (true) {
            // reset permission checker to use our license
            licenseManager.updatePermissionChecker();

            GUIUtils.runModalJFrame(loadCompetitionWindow);

            if (loadCompetitionWindow.getSuccess()) {
                DatabaseInfo info = loadCompetitionWindow.getSelectedDatabaseInfo();

                if (!databaseManager.checkLock(info.id)) {
                    String message = "EventManager did not shut down correctly the last time this competition was open. To avoid potential data corruption, you are advised to take the following steps:\n"
                            + "1) Do NOT open this competition\n" + "2) Create a backup of this competition\n"
                            + "3) Delete the competition from this computer\n"
                            + "4) If possible, reload this competition from another computer on the network\n"
                            + "5) Alternatively, you may manually load the backup onto all computers on the network, ensuring the 'Preserve competition ID' option is checked.";
                    String title = "WARNING: Potential Data Corruption Detected";

                    int status = JOptionPane.showOptionDialog(null, message, title, JOptionPane.YES_NO_OPTION,
                            JOptionPane.ERROR_MESSAGE, null,
                            new Object[] { "Cancel (recommended)", "Open anyway" }, "Cancel (recommended)");

                    if (status == 0)
                        continue; // return to load competition window
                }

                SynchronizingWindow syncWindow = new SynchronizingWindow();
                syncWindow.setVisible(true);
                long t = System.nanoTime();
                DistributedDatabase database = databaseManager.activateDatabase(info.id, info.passwordHash);
                long dt = System.nanoTime() - t;
                log.debug(String.format("Initial sync in %dms",
                        TimeUnit.MILLISECONDS.convert(dt, TimeUnit.NANOSECONDS)));
                syncWindow.dispose();

                if (loadCompetitionWindow.isNewDatabase()) {
                    GregorianCalendar calendar = new GregorianCalendar();
                    Date today = calendar.getTime();
                    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
                    calendar.set(Calendar.DAY_OF_MONTH, 31);
                    Date endOfYear = new java.sql.Date(calendar.getTimeInMillis());

                    CompetitionInfo ci = new CompetitionInfo();
                    ci.setName(info.name);
                    ci.setStartDate(today);
                    ci.setEndDate(today);
                    ci.setAgeThresholdDate(endOfYear);
                    //ci.setPasswordHash(info.passwordHash);
                    License license = licenseManager.getLicense();
                    if (license != null) {
                        ci.setLicenseName(license.getName());
                        ci.setLicenseType(license.getType().toString());
                        ci.setLicenseContact(license.getContactPhoneNumber());
                    }
                    database.add(ci);
                }

                // Set PermissionChecker to use database's license type
                String competitionLicenseType = database.get(CompetitionInfo.class, null).getLicenseType();
                PermissionChecker.setLicenseType(LicenseType.valueOf(competitionLicenseType));

                TransactionNotifier notifier = new TransactionNotifier();
                database.setListener(notifier);

                MainWindow mainWindow = new MainWindow();
                mainWindow.setDatabase(database);
                mainWindow.setNotifier(notifier);
                mainWindow.setPeerManager(peerManager);
                mainWindow.setLicenseManager(licenseManager);
                mainWindow.setManualDiscoveryService(manualDiscoveryService);
                mainWindow.setTitle(WINDOW_TITLE);
                mainWindow.afterPropertiesSet();

                TestUtil.setActivatedDatabase(database);

                // show main window (modally)
                GUIUtils.runModalJFrame(mainWindow);

                // shutdown procedures

                // System.exit();

                database.shutdown();
                databaseManager.deactivateDatabase(1500);

                if (mainWindow.getDeleteOnExit()) {
                    for (File file : info.localDirectory.listFiles())
                        if (!file.isDirectory())
                            file.delete();
                    info.localDirectory.deleteOnExit();
                }
            } else {
                // This can cause an RuntimeException - Peer is disconnected
                peerManager.stop();
                System.exit(0);
            }
        }
    } catch (Throwable e) {
        log.error("Error in main function", e);
        String message = e.getMessage();
        if (message == null)
            message = "";
        if (message.length() > 100)
            message = message.substring(0, 97) + "...";
        GUIUtils.displayError(null,
                "An unexpected error has occured.\n\n" + e.getClass().getSimpleName() + "\n" + message);
        System.exit(0);
    }
}

From source file:FocusTraversalDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {/* ww w .java2  s.co 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.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:events.FocusEventDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {// w w w.  ja  va2s  .  c o m
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        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 dispatch thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:ru.develgame.jflickrorganizer.MainClass.java

public static void main(String args[]) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainClass.class);

    try {//w w  w  . j av a  2  s .  c  o m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
    }

    context.getBean(LoginForm.class).setVisible(true);
}

From source file:edu.harvard.mcz.imagecapture.ImageCaptureApp.java

/**Main method for starting the application.
 * //from  w  w  w.java  2 s.co m
 * @param args are not used.
 */
public static void main(String[] args) {

    log.debug(UIManager.getLookAndFeel());
    log.debug(UIManager.getLookAndFeel().getID());

    if (UIManager.getLookAndFeel().getID().equals("Aqua")) {
        // check for "Aqua"
        try {
            UIManager.setLookAndFeel(
                    // OSX Aqua look and feel uses space on forms much too inefficiently
                    // switch to the normal Java look and feel instead.
                    UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            log.error(e);
        } catch (ClassNotFoundException e) {
            log.error(e);
        } catch (InstantiationException e) {
            log.error(e);
        } catch (IllegalAccessException e) {
            log.error(e);
        }
    }

    System.out.println("Starting " + APP_NAME + " " + APP_VERSION);
    System.out.println(APP_COPYRIGHT);
    System.out.println(APP_LICENSE);
    log.debug("Starting " + APP_NAME + " " + APP_VERSION);

    // open UI and start
    MainFrame mainFrame = new MainFrame();
    Singleton.getSingletonInstance().setMainFrame(mainFrame);
    Singleton.getSingletonInstance().getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    Singleton.getSingletonInstance().unsetCurrentUser();
    Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Starting....");
    log.debug("User interface started");

    // Load properties
    ImageCaptureProperties properties = new ImageCaptureProperties();
    Singleton.getSingletonInstance().setProperties(properties);
    log.debug("Properties loaded");

    // Set up a barcode (text read from barcode label for pin) matcher/builder
    if (Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_COLLECTION)
            .equals(ImageCaptureProperties.COLLECTION_MCZENT)) {
        // ** Configured for the MCZ Entomology Collection, use MCZ assumptions.
        MCZENTBarcode barcodeTextBuilderMatcher = new MCZENTBarcode();
        Singleton.getSingletonInstance().setBarcodeBuilder((BarcodeBuilder) barcodeTextBuilderMatcher);
        Singleton.getSingletonInstance().setBarcodeMatcher((BarcodeMatcher) barcodeTextBuilderMatcher);
    } else if (Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_COLLECTION)
            .equals(ImageCaptureProperties.COLLECTION_ETHZENT)) {
        // ** Configured for the ETHZ Entomology Collection, use MCZ assumptions.
        ETHZBarcode barcodeTextBuilderMatcher = new ETHZBarcode();
        Singleton.getSingletonInstance().setBarcodeBuilder((BarcodeBuilder) barcodeTextBuilderMatcher);
        Singleton.getSingletonInstance().setBarcodeMatcher((BarcodeMatcher) barcodeTextBuilderMatcher);
    } else {
        log.error("Configured collection not recognized.  Unable to Start");
        ImageCaptureApp.exit(EXIT_ERROR);
    }

    // Force a login dialog by connecting to obtain record count;
    SpecimenLifeCycle sls = new SpecimenLifeCycle();
    try {
        Singleton.getSingletonInstance().getMainFrame().setCount(sls.findSpecimenCountThrows());
        ImageCaptureApp.doStartUp();
    } catch (ConnectionException e) {
        log.error(e.getMessage());
        ImageCaptureApp.doStartUpNot();
    }

    // Experimental chat support, working on localhost.

    /** 
            
       Context context = null;
       Hashtable contextProperties = new Hashtable(2);
            
       contextProperties.put(Context.PROVIDER_URL,"iiop://127.0.0.1:3700");
       contextProperties.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
       contextProperties.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
       contextProperties.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
       try {
    context = new InitialContext(contextProperties);
       } catch (NamingException ex) {
    ex.printStackTrace();
       }
       if (context!=null) { 
    ConnectionFactory connectionFactory;
    try {
       connectionFactory = (ConnectionFactory)context.lookup("jms/InsectChatTopicFactory");
       Topic chatTopic = (Topic)context.lookup("jms/InsectChatTopic");
       TopicConnection connection = (TopicConnection) connectionFactory.createConnection();
       TopicSession session = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
       TopicSubscriber subscriber = session.createSubscriber(chatTopic);
       connection.start();
       while (true) {
          Message m = subscriber.receive(1);
          if (m != null) {
             if (m instanceof TextMessage) {
                TextMessage message = (TextMessage) m;
                String originator = message.getStringProperty("Originator");
                String text = message.getText();
                System.out.println("Message: " + originator + ": " + text);
             } else {
                break;
             }
          }
       }
    } catch (NamingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    } catch (JMSException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }
       }
    } 
      */

}

From source file:edu.ku.brc.specify.extras.FixSQLString.java

/**
 * @param args// w ww .  j a va  2s.co  m
 */
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @SuppressWarnings("synthetic-access")
        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) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelClassGenerator.class, e);
                //log.error("Can't change L&F: ", e);
            }
            FixSQLString fix = new FixSQLString();
            fix.setVisible(true);

        }
    });
}

From source file:EditorPaneExample9.java

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

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

From source file:FocusEventDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {/*from   www  .j  ava  2s  .  co  m*/
        // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        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 dispatch thread:
    // creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:SampleTableModel.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override//from ww  w.  j a va2  s  .c  o m
        public void run() {
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (Exception e) {
            }

            JFrame frame = new JFrame("Swing JTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JApplet applet = new SwingInterop();
            applet.init();

            frame.setContentPane(applet.getContentPane());

            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);

            //               applet.start();
        }
    });
}