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

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel gui = new JPanel(new BorderLayout(5, 5));

    JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
    plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)"));

    UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
    String[] plafNames = new String[plafInfos.length];
    for (int ii = 0; ii < plafInfos.length; ii++) {
        plafNames[ii] = plafInfos[ii].getName();
    }//from   w w w.  ja  v  a 2s .c  om
    JComboBox plafChooser = new JComboBox(plafNames);
    plafComponents.add(plafChooser);

    JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
    plafComponents.add(pack);

    plafChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int index = plafChooser.getSelectedIndex();
            try {
                UIManager.setLookAndFeel(plafInfos[index].getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                if (pack.isSelected()) {
                    frame.pack();
                    frame.setMinimumSize(frame.getSize());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    gui.add(plafComponents, BorderLayout.NORTH);

    JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
    dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)"));
    gui.add(dynamicLabels, BorderLayout.WEST);

    final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3));
    labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)"));

    JButton addNew = new JButton("Add Another Label");
    dynamicLabels.add(addNew, BorderLayout.NORTH);
    addNew.addActionListener(new ActionListener() {

        private int labelCount = 0;

        public void actionPerformed(ActionEvent ae) {
            labels.add(new JLabel("Label " + ++labelCount));
            frame.validate();
        }
    });

    dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER);

    String[] header = { "Name", "Value" };
    String[] a = new String[0];
    String[] names = System.getProperties().stringPropertyNames().toArray(a);
    String[][] data = new String[names.length][2];
    for (int ii = 0; ii < names.length; ii++) {
        data[ii][0] = names[ii];
        data[ii][1] = System.getProperty(names[ii]);
    }
    DefaultTableModel model = new DefaultTableModel(data, header);
    JTable table = new JTable(model);

    JScrollPane tableScroll = new JScrollPane(table);
    Dimension tablePreferred = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));

    JPanel imagePanel = new JPanel(new GridBagLayout());
    JLabel imageLabel = new JLabel("test");
    imagePanel.add(imageLabel, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel));
    gui.add(splitPane, BorderLayout.CENTER);

    frame.setContentPane(gui);
    frame.pack();
    frame.setVisible(true);
}

From source file:de.ep3.ftpc.App.java

public static void main(String[] args) {
    try {/*from   w  ww . j a va  2 s.  c o m*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }

    Controller e = getContext().getBean("exceptionController", Controller.class);

    e.dispatch();

    Controller c = getContext().getBean("portalFrameController", Controller.class);

    c.dispatch();
}

From source file:inc.cygnus.app.MainSpring.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                // Implementasi Konfigurasi Spring framework
                @SuppressWarnings("resource")
                ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");

                // Initialize service
                setCustomerService((CustomerService) appContext.getBean("customerService"));
                setProductService((ProductService) appContext.getBean("productService"));
                setPurchaseService((PurchaseService) appContext.getBean("purchaseService"));

                try {
                    // After finish service initialize
                    // Show Form Menu Master
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(MainSpring.class.getName()).log(Level.SEVERE, null, ex);
                }//from  ww  w  .ja  v a  2s .  c om
                Menu mmv = new Menu();

                mmv.setVisible(true);

            } catch (BeansException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:FormattedTextFieldExample.java

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

    JFrame f = new JFrame("Formatted Text Field");
    final FormattedTextField tf = new FormattedTextField();

    FormattedTextField.FormatSpec formatSpec = new FormattedTextField.FormatSpec("(...)-...-....",
            "(***)-***-****");
    tf.setFormatSpec(formatSpec);
    f.getContentPane().add(tf, "Center");
    f.getContentPane().add(new JLabel("Phone Number: ", JLabel.RIGHT), "West");

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Field content is <" + tf.getText() + ">");
        }
    });

    f.pack();
    f.setVisible(true);
}

From source file:de.dakror.jagui.parser.NGuiParser.java

public static void main(String[] args) {
    try {/*from  ww  w .j  a v a2s . c om*/
        DIR.mkdirs();
        if (!new File(DIR, "convert.exe").exists())
            Helper.copyInputStream(NGuiParser.class.getResourceAsStream("/res/convert.exe"),
                    new FileOutputStream(new File(DIR, "convert.exe")));

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        JFileChooser jfc = new JFileChooser(
                new File(NGuiParser.class.getProtectionDomain().getCodeSource().getLocation().toURI()));
        jfc.setMultiSelectionEnabled(false);
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.setFileFilter(new FileNameExtensionFilter("Unity ngui Gui-Skin (*.guiskin)", "guiskin"));

        if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            p("Collecting GUIDs, Converting Resources");
            HashMap<String, File> guids = collectGUIDs(jfc.getCurrentDirectory());

            p("Parsing Guiskin file");
            String s = Helper.getFileContent(jfc.getSelectedFile());
            String[] lines = s.split("\n");
            ArrayList<String> l = new ArrayList<>(Arrays.asList(lines));
            String string = "";
            for (int i = 0; i < l.size(); i++)
                if (!l.get(i).startsWith("%") && !l.get(i).startsWith("---"))
                    string += l.get(i) + "\n";

            Yaml yaml = new Yaml();
            for (Iterator<Object> iter = yaml.loadAll(string).iterator(); iter.hasNext();) {
                JSONObject o = new JSONObject((Map<?, ?>) iter.next());
                p("Cconverting Guiskin");
                replaceGuidDeep(o, guids, jfc.getSelectedFile());
                p("Writing converted file");
                Helper.setFileContent(new File(jfc.getSelectedFile().getParentFile(),
                        jfc.getSelectedFile().getName() + ".json"), o.toString(4));
                p("DONE");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:BoundedTextField.java

public static void main(String[] args) {
    try {//from 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 JFrame("Bounded Text Field Example");
    BoundedTextField tf = new BoundedTextField(10, 32);
    JLabel l = new JLabel("Type up to 32 characters: ");
    f.getContentPane().add(tf, "East");
    f.getContentPane().add(l, "West");
    f.pack();
    f.setVisible(true);
}

From source file:ua.com.fielden.platform.example.swing.schedule.ScheduleChartPanelExample.java

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

        @Override//www . j  ava2s .  com
        public void run() {
            for (final LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(laf.getName())) {
                    try {
                        UIManager.setLookAndFeel(laf.getClassName());
                    } catch (final Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            com.jidesoft.utils.Lm.verifyLicense("Fielden Management Services", "Rollingstock Management System",
                    "xBMpKdqs3vWTvP9gxUR4jfXKGNz9uq52");
            LookAndFeelFactory.installJideExtension();
            final JFrame frame = new JFrame("Scedule chart demo");
            final JLabel label = new JLabel("None");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new MigLayout("fill, insets 0", "[grow, fill]", "[grow, fill][]"));
            frame.add(createScheduleChartPanel(label), "wrap");
            frame.add(label);
            frame.setPreferredSize(new Dimension(640, 480));
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:misc.TrayIconDemo.java

public static void main(String[] args) {
    /* Use an appropriate Look and Feel */
    try {/*from   w ww .j av a 2 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:
    //adding TrayIcon.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:info.varden.anatychia.Main.java

/**
 * @param args the command line arguments
 *//*from  w w w  .ja v a2 s  .com*/
public static void main(String[] args) {
    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (Exception e) {
        // If Nimbus is not available, you can set the GUI to another look and feel.
    }
    // SaveData sd = new SaveData(new File("C:\\Users\\Marius\\AppData\\Roaming\\.minecraft\\saves\\Craft Bandicoot World 1.0"), "Craft Bandicoot World 1.0", "Craft Bandicoot World 1.0");
    // materialList(sd);
    AnatychiaMain mn = new AnatychiaMain();
    mn.setLocationRelativeTo(null);
    mn.setVisible(true);
    //SplashScreen.main(args);
    /*final DoubleTag it = new DoubleTag("Test", 1.4D);
    final CompoundTag ct1 = new CompoundTag("someStore", new HashMap<String, Tag>() {{
    put("Test", it);
    }});
    CompoundTag root = new CompoundTag("", new HashMap<String, Tag>() {{
    put("someStore", ct1);
    }});
    MaterialData d = new MaterialData(MaterialType.BLOCK, "minecraft:air", 0, new NBTCriteria[] {
    new NBTCriteria("/someStore/Test", DoubleTag.class, "2", MatchMode.EQUALS_OR_SMALLER),
    new NBTCriteria("/someStore/Test", DoubleTag.class, "1.5", MatchMode.EQUALS_OR_GREATER)
    });
    System.out.println(d.fulfillsRequirements(root));*/
}

From source file:aurelienribon.texturepackergui.Main.java

public static void main(String[] args) {
    Parameters params = new Parameters(args);
    Project project = params.project;/*w w w . ja  v  a2s. c o m*/

    if (project == null) {
        String str = "";
        str += "input=" + params.input + "\n";
        str += "output=" + params.output + "\n";
        str += params.settings;
        project = Project.fromString(str);
    }

    if (params.silent) {
        if (project.input.equals("") || project.output.equals("")) {
            System.err.println("Input and output directories have to be set");
        } else {
            try {
                project.pack();
            } catch (GdxRuntimeException ex) {
                System.err.println("Packing unsuccessful. " + ex.getMessage());
            }
        }
        return;
    }

    final Project prj = project;
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException ex) {
            } catch (InstantiationException ex) {
            } catch (IllegalAccessException ex) {
            } catch (UnsupportedLookAndFeelException ex) {
            }

            Canvas canvas = new Canvas();
            LwjglCanvas glCanvas = new LwjglCanvas(canvas, true);

            MainWindow mw = new MainWindow(prj, canvas, glCanvas.getCanvas());
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            mw.setSize(Math.min(1100, screenSize.width - 100), Math.min(670, screenSize.height - 100));
            mw.setLocationRelativeTo(null);
            mw.setVisible(true);
        }
    });
}