Example usage for javax.swing SwingUtilities updateComponentTreeUI

List of usage examples for javax.swing SwingUtilities updateComponentTreeUI

Introduction

In this page you can find the example usage for javax.swing SwingUtilities updateComponentTreeUI.

Prototype

public static void updateComponentTreeUI(Component c) 

Source Link

Document

A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(300, 300);/*from w  w w  .j a v  a  2  s.co  m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("System LAF Demo");

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }

    SwingUtilities.updateComponentTreeUI(frame);

    frame.setVisible(true);
}

From source file:ChangeLook.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("Change Look");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String lafClassName = null;
            lafClassName = actionEvent.getActionCommand();
            String finalLafClassName = lafClassName;
            try {
                UIManager.setLookAndFeel(finalLafClassName);
                SwingUtilities.updateComponentTreeUI(frame);
            } catch (Exception exception) {
                JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                        JOptionPane.ERROR_MESSAGE);
            }/*from  w w w  .  j  a va  2 s  .  c o  m*/

        }
    };

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    JComboBox comboBox = new JComboBox(new String[] { "a", "b" });

    JPanel panel = new JPanel();

    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        panel.add(button);
    }

    frame.add(comboBox, BorderLayout.NORTH);
    frame.add(panel, BorderLayout.SOUTH);
    frame.setSize(350, 150);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(final String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 300);//from   www.j  av a 2 s .c  om
    f.setLocationRelativeTo(null);

    f.setUndecorated(true);
    f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

    JPanel panel = new JPanel();
    panel.setBackground(java.awt.Color.white);
    f.setContentPane(panel);

    MetalLookAndFeel.setCurrentTheme(new MyDefaultMetalTheme());
    try {
        UIManager.setLookAndFeel(new MetalLookAndFeel());
    } catch (Exception e) {
        e.printStackTrace();
    }

    SwingUtilities.updateComponentTreeUI(f);

    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String[] properties = { "os.name", "java.version", "java.vm.version", "java.vendor" };
    for (String property : properties) {
        System.out.println(property + ": " + System.getProperty(property));
    }//from  w  w w.ja  v a 2s .  c  o  m
    JFileChooser jfc = new JFileChooser();
    jfc.showOpenDialog(null);
    jfc.addChoosableFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".obj");
        }

        @Override
        public String getDescription() {
            return "Wavefront OBJ (*.obj)";
        }

        @Override
        public String toString() {
            return getDescription();
        }
    });
    int result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(jfc);
    jfc.showOpenDialog(null);
    result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");

    result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");
    for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            SwingUtilities.updateComponentTreeUI(jfc);
            break;
        }
    }
    jfc.showOpenDialog(null);
    result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?");
}

From source file:MainClass.java

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

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Object source = actionEvent.getSource();
            String lafClassName = null;
            if (source instanceof JComboBox) {
                JComboBox comboBox = (JComboBox) source;
                lafClassName = (String) comboBox.getSelectedItem();
            } else if (source instanceof JButton) {
                lafClassName = actionEvent.getActionCommand();
            }//from  w ww .j  a  va 2  s .c  o m
            if (lafClassName != null) {
                final String finalLafClassName = lafClassName;
                try {
                    UIManager.setLookAndFeel(finalLafClassName);
                    SwingUtilities.updateComponentTreeUI(frame);
                } catch (Exception exception) {
                    JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    };

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    DefaultComboBoxModel model = new DefaultComboBoxModel();
    JComboBox comboBox = new JComboBox(model);

    JPanel panel = new JPanel();

    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        model.addElement(looks[i].getClassName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        panel.add(button);
    }

    comboBox.addActionListener(actionListener);

    frame.add(comboBox, BorderLayout.NORTH);
    frame.add(panel, BorderLayout.SOUTH);
    frame.setSize(350, 150);
    frame.setVisible(true);
}

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  a2  s  .  co  m
    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.alpharogroup.duplicate.files.desktoppane.MainApplication.java

/**
 * The main method./* w ww  .  j ava2  s . c  om*/
 *
 * @param args
 *            the arguments
 */
public static void main(final String[] args) {

    final ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext();
    final Resource resource = ctx.getResource("classpath:conf/log4j/log4jconfig.xml");

    try {
        DOMConfigurator.configure(resource.getURL());
    } catch (final FactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final MainFrame mainFrame = MainFrame.getInstance();
    final DesktopMenu menu = DesktopMenu.getInstance();
    mainFrame.setJMenuBar(menu.getMenubar());

    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setSize(ScreenSizeExtensions.getScreenWidth(), ScreenSizeExtensions.getScreenHeight());
    mainFrame.setVisible(true);
    mainFrame.getDesktopPane().getDesktopManager().activateFrame(mainFrame.getInternalFrame());
    mainFrame.getDesktopPane().getDesktopManager().maximizeFrame(mainFrame.getInternalFrame());
    mainFrame.getInternalFrame().toFront();

    // Set default look and feel...
    try {
        UIManager.setLookAndFeel(LookAndFeels.SYSTEM.getLookAndFeelName());
        SwingUtilities.updateComponentTreeUI(mainFrame);
        mainFrame.setCurrentLookAndFeels(LookAndFeels.SYSTEM);
    } catch (final ClassNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (final InstantiationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (final IllegalAccessException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (final UnsupportedLookAndFeelException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

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  ww.  j a  va  2 s  .co 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:ListProperties.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("List Properties");

    final CustomTableModel model = new CustomTableModel();
    model.uiDefaultsUpdate(UIManager.getDefaults());
    TableSorter sorter = new TableSorter(model);

    JTable table = new JTable(sorter);
    TableHeaderSorter.install(sorter, table);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            final String lafClassName = actionEvent.getActionCommand();
            Runnable runnable = new Runnable() {
                public void run() {
                    try {
                        UIManager.setLookAndFeel(lafClassName);
                        SwingUtilities.updateComponentTreeUI(frame);
                        // Added
                        model.uiDefaultsUpdate(UIManager.getDefaults());
                    } catch (Exception exception) {
                        JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                                JOptionPane.ERROR_MESSAGE);
                    }//ww  w.j a  v  a  2 s  .c  o m
                }
            };
            SwingUtilities.invokeLater(runnable);
        }
    };

    JToolBar toolbar = new JToolBar();
    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        toolbar.add(button);
    }

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
}

From source file:Main.java

public static void setLookAndFeel(String lafName, JFrame frame) {
    try {//from   w  ww .  j  a  v a  2s  .c o m
        UIManager.setLookAndFeel(lafName);
        if (frame != null) {
            SwingUtilities.updateComponentTreeUI(frame);
            frame.pack();
        }
    } catch (ClassNotFoundException e) {
        System.err.println("Could not find Look and Feel class!");
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.err.println("Could not instantiate Look and Feel class!");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        System.err.println("Could not access Look and Feel class!");
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        System.err.println("This Look and Feel is not supported!");
        e.printStackTrace();
    }
}