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

public static void main(String... args) {
    try {//from   w w w  .j a  va 2 s. c  o  m
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (UnsupportedLookAndFeelException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new TwoStopsGradient().setVisible(true);
        }
    });
}

From source file:DragDropTreeExample.java

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

    final JFrame f = new JFrame("FileTree Drop and Drop Example");
    try {
        final FileTree tree = new FileTree("D:\\");

        // Add a drop target to the FileTree
        FileTreeDropTarget target = new FileTreeDropTarget(tree);

        // Add a drag source to the FileTree
        FileTreeDragSource source = new FileTreeDragSource(tree);

        tree.setEditable(true);

        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) {
                tree.setEditable(editable.isSelected());
            }
        });

        final JCheckBox enabled = new JCheckBox("Enabled");
        enabled.setSelected(true);
        panel.add(enabled);
        enabled.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                tree.setEnabled(enabled.isSelected());
            }
        });

        f.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
        f.getContentPane().add(panel, BorderLayout.SOUTH);
        f.setSize(500, 400);
        f.setVisible(true);
    } catch (Exception e) {
        System.out.println("Failed to build GUI: " + e);
    }
}

From source file:com.jgoodies.validation.tutorial.formatted.NumberExample.java

public static void main(String[] args) {
    try {//  w w w .java2s  . c  o m
        UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
    } catch (Exception e) {
        // Likely Plastic is not in the classpath; ignore it.
    }
    JFrame frame = new JFrame();
    frame.setTitle("Formatted :: Numbers");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JComponent panel = new NumberExample().buildPanel();
    frame.getContentPane().add(panel);
    frame.pack();
    TutorialUtils.locateOnScreenCenter(frame);
    frame.setVisible(true);
}

From source file:daylightchart.Main.java

/**
 * Main window.//from   w w w .  j a  v a  2s . c  o m
 *
 * @param args
 *        Arguments
 */
public static void main(final String[] args) {

    CommandLineUtility.setLogLevel(args);

    // Parse command line
    final CommandLineParser parser = new CommandLineParser();
    parser.addOption(new BooleanOption(Option.NO_SHORT_FORM, OPTION_SLIMUI));
    parser.addOption(new StringOption(Option.NO_SHORT_FORM, OPTION_PREFERENCES, null));
    parser.addOption(new StringOption(Option.NO_SHORT_FORM, OPTION_LOCATION, null));
    parser.parse(args);
    boolean slimUi = parser.getBooleanOptionValue(OPTION_SLIMUI);
    final String preferencesDirectory = parser.getStringOptionValue(OPTION_PREFERENCES);
    final String locationString = parser.getStringOptionValue(OPTION_LOCATION);
    Location location = null;
    if (locationString != null) {
        try {
            location = LocationsListParser.parseLocation(locationString);
        } catch (final ParserException e) {
            location = null;
        }
    }

    if (StringUtils.isNotBlank(preferencesDirectory)) {
        UserPreferences.initialize(Paths.get(preferencesDirectory));
    }

    // Set UI look and feel
    try {
        PlasticLookAndFeel.setPlasticTheme(new LightGray());
        UIManager.setLookAndFeel(new PlasticLookAndFeel());
    } catch (final Exception e) {
        LOGGER.log(Level.WARNING, "Cannot set look and feel");
    }

    final Options options = UserPreferences.optionsFile().getData();
    if (!slimUi) {
        slimUi = options.isSlimUi();
    }
    options.setSlimUi(slimUi);
    UserPreferences.optionsFile().save(options);
    new DaylightChartGui(location, slimUi).setVisible(true);

}

From source file:EditorPaneExample3.java

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

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

From source file:commonline.query.gui.Frame.java

public static void main(String args[]) throws Exception {
    Plastic3DLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE);
    UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");

    System.setProperty("com.apple.macos.useScreenMenuBar", "true");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("MainContext.xml");

    List dataSources = new ArrayList();
    dataSources.addAll(context.getBeansOfType(RecordParserDataSource.class).values());
    CommonlineRecordRepository repository = (CommonlineRecordRepository) context.getBean("clRepository");

    Frame frame = new Frame(System.getProperty("os.name").toLowerCase().indexOf("mac") != -1, dataSources,
            repository);/*  www .j  a  v a2 s . co m*/
    frame.setVisible(true);
}

From source file:misc.FocusConceptsDemo.java

public static void main(String[] args) {

    /* Use an appropriate Look and Feel */
    try {//w w  w  . 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-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:NumericTextField.java

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

    DecimalFormat format = new DecimalFormat("#,###.###");
    format.setGroupingUsed(true);
    format.setGroupingSize(3);
    format.setParseIntegerOnly(false);

    JFrame f = new JFrame("Numeric Text Field Example");
    final NumericTextField tf = new NumericTextField(10, format);

    tf.setValue((double) 123456.789);

    JLabel lbl = new JLabel("Type a number: ");
    f.getContentPane().add(tf, "East");
    f.getContentPane().add(lbl, "West");

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                tf.normalize();
                Long l = tf.getLongValue();
                System.out.println("Value is (Long)" + l);
            } catch (ParseException e1) {
                try {
                    Double d = tf.getDoubleValue();
                    System.out.println("Value is (Double)" + d);
                } catch (ParseException e2) {
                    System.out.println(e2);
                }
            }
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:com.jgoodies.validation.tutorial.formatted.DateExample.java

public static void main(String[] args) {
    try {//from  www . j  a  v a2s .c  om
        UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
    } catch (Exception e) {
        // Likely Plastic is not in the classpath; ignore it.
    }
    JFrame frame = new JFrame();
    frame.setTitle("Formatted :: Dates");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JComponent panel = new DateExample().buildPanel();
    frame.getContentPane().add(panel);
    frame.pack();
    TutorialUtils.locateOnScreenCenter(frame);
    frame.setVisible(true);
}

From source file:jeplus.Main.java

/**
 * @param args the command line arguments
 *//*  w ww.  j a va  2s .c  o  m*/
public static void main(String[] args) {
    //        if (REDIRECT_ERR) {
    //            try {
    //                // Redirect err
    //                System.setErr(new PrintStream(new FileOutputStream("jeplus.err")));
    //            } catch (FileNotFoundException ex) {
    //                //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    //                ex.printStackTrace();
    //            }
    //        }

    try {
        // Set cross-platform Java L&F (also called "Metal")
        //            UIManager.setLookAndFeel(
        //                UIManager.getCrossPlatformLookAndFeelClassName());
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        //                if ("Nimbus".equals(info.getName())) {
        //                    UIManager.setLookAndFeel(info.getClassName());
        //                    break;
        //                }
        //            }
    } catch (UnsupportedLookAndFeelException e) {
        System.err.println("Unsupported Look-And-Feel Option. Reverting to the default UI.");
    } catch (ClassNotFoundException e) {
        System.err.println("Specified Look-And-Feel class cannot be found. Reverting to the default UI.");
    } catch (InstantiationException e) {
        System.err.println("Fialed to instantiate the specified Look-And-Feel. Reverting to the default UI.");
    } catch (IllegalAccessException e) {
        System.err.println("Cannot access the specified Look-And-Feel. Reverting to the default UI.");
    }

    // Set locale to UK
    Locale.setDefault(Locale.UK);
    // Set line end to DOS style
    System.setProperty("line.separator", "\r\n");
    // System.setProperty("file.separator", "/");  // seemed to have no effect

    // create the parser
    CommandLineParser parser = new GnuParser();
    Options options = new Main().getCommandLineOptions(null);
    CommandLine commandline = null;
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(80);
    try {
        // parse the command line arguments
        commandline = parser.parse(options, args);
        if (commandline.hasOption("help")) {
            // automatically generate the help statement
            formatter.printHelp("java -Xmx1000m -jar jEPlus.jar [OPTIONS]", options);
            System.exit(-1);
        }
        // Set log4j configuration
        if (commandline.hasOption("log")) {
            PropertyConfigurator.configure(commandline.getOptionValue("log"));
        } else {
            PropertyConfigurator.configure("log4j.cfg");
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        // automatically generate the help statement
        formatter.printHelp("java -Xmx1000m -jar jEPlus.jar [OPTIONS]", options);
        System.exit(-1);
    }

    // Call main fuction with commandline
    new Main().mainFunction(commandline);
}