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:MainProgram.MainProgram.java

public static void main(String[] args) throws InterruptedException, FileNotFoundException {
    MainFrame mainFrame = new MainFrame();
    errorLog = new PrintStream(file);
    try {/*from w  w w.j  ava2s  . c o m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
        ex.printStackTrace(errorLog);
        Logger.getLogger(MainProgram.class.getName()).log(Level.SEVERE, null, ex);
    }
    SwingUtilities.updateComponentTreeUI(mainFrame);
    mainFrame.setVisible(true);
    mainFrame.setSize(445, 415);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setResizable(false);

}

From source file:groovesquid.Main.java

public static void main(String[] args) {

    System.setSecurityManager(null);

    log.log(Level.INFO, "Groovesquid v{0} running on {1} {2} ({3}) in {4}",
            new Object[] { version, System.getProperty("java.vm.name"),
                    System.getProperty("java.runtime.version"), System.getProperty("java.vm.vendor"),
                    System.getProperty("java.home") });

    // show gui//from   w w w. j a v  a2s  .  c  o  m

    // apple os x
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Groovesquid");
    // antialising
    System.setProperty("awt.useSystemAAFontSettings", "lcd");
    System.setProperty("swing.aatext", "true");
    // flackering bg fix
    System.setProperty("sun.awt.noerasebackground", "true");
    System.setProperty("sun.java2d.noddraw", "true");
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

    try {
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        log.log(Level.SEVERE, null, ex);
    }

    // load languages
    languages = loadLanguages();

    // Load config
    config = loadConfig();

    // GUI
    try {
        gui = (GUI) config.getGuiClass().newInstance();
    } catch (InstantiationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    settings = new Settings();
    about = new About();

    // Update Checker
    new UpdateCheckThread().start();

    // init grooveshark (every 25min)
    new InitThread().start();

}

From source file:net.frontlinesms.DesktopLauncher.java

/**
 * Main class for launching the FrontlineSMS project.
 * @param args/*  w w  w . j  a v  a  2 s .  c om*/
 */
public static void main(String[] args) {
    FrontlineSMS frontline = null;
    try {
        AppProperties appProperties = AppProperties.getInstance();
        final String VERSION = BuildProperties.getInstance().getVersion();
        LOG.info("FrontlineSMS version [" + VERSION + "]");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        String lastVersion = appProperties.getLastRunVersion();
        InputStream defaultResourceArchive = ResourceUtils.class.getResourceAsStream("/resources.zip");
        if (defaultResourceArchive == null) {
            LOG.fatal("Default resources archive could not be found!");
            throw new Exception("Default resources archive could not be found!");
        }

        ResourceUtils.unzip(defaultResourceArchive, new File(ResourceUtils.getConfigDirectoryPath()),
                !VERSION.equals(lastVersion));

        // This should always get the English bundle, as other languages are only included in
        // resources.zip rather than in the resources/languages directory
        LanguageBundle englishBundle = InternationalisationUtils.getDefaultLanguageBundle();
        Thinlet.DEFAULT_ENGLISH_BUNDLE = englishBundle.getProperties();

        // If the user has currently no User ID defined
        // We generate one
        if (appProperties.getUserId() == null) {
            appProperties.setUserId(generateUserId());
        }

        boolean showWizard = appProperties.isShowWizard();
        appProperties.setLastRunVersion(VERSION);
        appProperties.saveToDisk();

        frontline = initFrontline();
        if (showWizard) {
            new FirstTimeWizard(frontline);
        } else {
            // Auto-detect phones.
            new UiGeneratorController(frontline, true);
        }
    } catch (Throwable t) {
        if (frontline != null)
            frontline.destroy();

        // Rather than swallowing the error, we now display it to the user
        // so that they can give us some feedback :)
        ErrorUtils.showErrorDialog("Fatal error starting FrontlineSMS!",
                "A problem ocurred during FrontlineSMS startup.", t, true);
    }
}

From source file:StylesExample7.java

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

    JFrame f = new JFrame("Styles Example 7");

    // Create the StyleContext, the document and the pane
    final StyleContext sc = new StyleContext();
    final DefaultStyledDocument doc = new DefaultStyledDocument(sc);
    final JTextPane pane = new JTextPane(doc);

    // Build the styles
    createDocumentStyles(sc);

    try {
        // Add the text and apply the styles
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                // Add the text
                addText(pane, sc, sc.getStyle(mainStyleName), content);
            }
        });
    } catch (Exception e) {
        System.out.println("Exception when constructing document: " + e);
        System.exit(1);
    }

    f.getContentPane().add(new JScrollPane(pane));
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {

    try {/*ww  w.j a  v  a 2 s . com*/
        String cn = UIManager.getSystemLookAndFeelClassName();
        UIManager.setLookAndFeel(cn); // Use the native L&F
    } catch (Exception cnf) {
    }
    PrinterJob job = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PageFormat pf = job.pageDialog(aset);
    job.setPrintable(new Main(), pf);
    boolean ok = job.printDialog(aset);
    if (ok) {
        try {
            job.print(aset);
        } catch (PrinterException ex) {
            /* The job did not successfully complete */
        }
    }
    System.exit(0);
}

From source file:PrintDialogExample.java

public static void main(String args[]) {

    try {//from  w ww.  j a va2  s.  com
        String cn = UIManager.getSystemLookAndFeelClassName();
        UIManager.setLookAndFeel(cn); // Use the native L&F
    } catch (Exception cnf) {
    }
    PrinterJob job = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PageFormat pf = job.pageDialog(aset);
    job.setPrintable(new PrintDialogExample(), pf);
    boolean ok = job.printDialog(aset);
    if (ok) {
        try {
            job.print(aset);
        } catch (PrinterException ex) {
            /* The job did not successfully complete */
        }
    }
    System.exit(0);
}

From source file:WindowEventDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {//from  www .j  a va 2 s.c om
        // 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 dispatch thread:
    // creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:JLabelDragSource.java

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

    JFrame f = new JFrame("Draggable JLabel");
    JLabel label = new JLabel("Drag this text", JLabel.CENTER);
    label.setFont(new Font("Serif", Font.BOLD, 32));
    f.getContentPane().add(label);
    f.pack();
    f.setVisible(true);

    // Attach the drag source
    JLabelDragSource dragSource = new JLabelDragSource(label);
}

From source file:misc.ModalityDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {/*from  w  w  w . j a v  a2  s. 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-dispatching thread:
    //creating and showing this application's GUI.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            ModalityDemo md = new ModalityDemo();
            md.createAndShowGUI();
            md.start();
        }
    });
}

From source file:org.jfree.graphics2d.demo.SwingUIToSVGDemo.java

public static void main(String[] args) {
    try {//ww  w  .j  av  a2 s .c om
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (Exception e) {
        // just take the default look and feel
    }

    SwingUIToSVGDemo app = new SwingUIToSVGDemo("SwingUIToSVGDemo.java");
    app.pack();
    app.setVisible(true);

}