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

static void setSwingLAF(java.awt.Component comp, String targetTheme) {

    try {//ww w.j  a v  a  2  s .c o  m
        if (targetTheme.equalsIgnoreCase(Native)) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } else if (targetTheme.equalsIgnoreCase(Java)) {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } else if (targetTheme.equalsIgnoreCase(Motif)) {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        }

        //            if (targetTheme.equalsIgnoreCase(plaf)){
        //                UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        //            }
        //
        //            if (targetTheme.equalsIgnoreCase(GTK)){
        //                UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        //            }
        SwingUtilities.updateComponentTreeUI(comp);

        if (comp instanceof java.awt.Frame) {
            ((java.awt.Frame) comp).pack();
        }
    } catch (Exception e) {
        errorMessage(e);
    }
}

From source file:Main.java

/**
 * Creates a sub-menu for changing Look'n'Feel.
 * @param rootComponent the root component which Look'n'Feel should be changed (child component are processed recursively).
 * @return a menu item with sub-menu items for each Look'n'Feel
 * installed in the system with associated actions to change the
 * Look'n'Feel for the <code>rootComponent</root>.
 *///from   www  .j a va  2  s .  c  o  m
public static JMenu getLafMenu(final Component rootComponent) {
    JMenu jMenu = new JMenu("Look & Feel");
    ButtonGroup buttonGroup = new ButtonGroup();
    final UIManager.LookAndFeelInfo[] installedLFs = UIManager.getInstalledLookAndFeels();
    String currentLF = UIManager.getLookAndFeel().getName();
    for (int i = 0; i < installedLFs.length; i++) {
        JCheckBoxMenuItem jMenuItem = new JCheckBoxMenuItem(installedLFs[i].getName());
        jMenu.add(jMenuItem);
        buttonGroup.add(jMenuItem);
        jMenuItem.setState(currentLF.equals(installedLFs[i].getName()));
        class ChangeLF extends AbstractAction {
            private UIManager.LookAndFeelInfo iLF;

            public ChangeLF(UIManager.LookAndFeelInfo iLF) {
                super(iLF.getName());
                this.iLF = iLF;
            }

            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(iLF.getClassName());
                    SwingUtilities.updateComponentTreeUI(rootComponent);
                } catch (Exception ex) {
                    System.out.print("Could not set look and feel: " + ex.toString());
                }
            }
        }
        jMenuItem.setAction(new ChangeLF(installedLFs[i]));
    }
    return jMenu;
}

From source file:Main.java

public static void lookWindows(Component comp) {
    UIManager.LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo look : looks) {
        if (look.getClassName().matches("(?i).*windows.*")) {
            try {
                UIManager.setLookAndFeel(look.getClassName());
                //               UIManager.put("ProgressBar.background", Color.DARK_GRAY); 
                //               UIManager.put("ProgressBar.foreground", Color.DARK_GRAY);
                //               UIManager.put("ProgressBar.selectionBackground",Color.DARK_GRAY); 
                //               UIManager.put("ProgressBar.selectionForeground",Color.DARK_GRAY); 
                //               UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel");
                //               UIManager.put("Synthetica.window.opaque", false);
                //               UIManager.put("Synthetica.window.shape", "");
                //               UIManager.put("Panel.background", Color.decode("#a5ddfb"));
                //               UIManager.put("RadioButton.background", Color.decode("#a5ddfb"));
                //               UIManager.put("CheckBox.background", Color.decode("#a5ddfb"));
                //               UIManager.put("MenuBar.background", Color.decode("#a5ddfb"));

                SwingUtilities.updateComponentTreeUI(comp);
                return;
            } catch (Exception e) {
                e.printStackTrace();//  w  w w . j a  v  a  2s.c o m
            }
        }
    }
}

From source file:Main.java

/**
 * Updates the componentTreeUI of the given window and all its
 * owned windows, recursively./* w  w  w  .j a  va2 s . com*/
 * 
 * 
 * @param window the window to update
 */
public static void updateAllComponentTreeUIs(Window window) {
    SwingUtilities.updateComponentTreeUI(window);
    for (Window owned : window.getOwnedWindows()) {
        updateAllComponentTreeUIs(owned);
    }
}

From source file:Main.java

public static void lookNimbus(Component comp) {
    UIManager.LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo look : looks) {
        if (look.getClassName().matches("(?i).*nimbus.*")) {
            try {
                UIManager.setLookAndFeel(look.getClassName());

                //                UIManager.put("control", Color.decode("#cccccc"));
                UIManager.put("info", Color.decode("#ff9900"));
                //                UIManager.put("nimbusAlertYellow", Color.decode("#ff0000"));
                //                UIManager.put("nimbusBase", Color.decode("#4e5a66"));
                //                UIManager.put("nimbusDisabledText", Color.decode("#9900ff"));
                UIManager.put("nimbusFocus", Color.decode("#ff9933"));
                //                UIManager.put("nimbusGreen", new Color(130, 133, 37));
                //                UIManager.put("nimbusInfoBlue", Color.decode("#9900ff"));
                //                UIManager.put("nimbusLightBackground", Color.decode("#9900ff"));
                //                UIManager.put("nimbusOrange", new Color(191, 98, 4));
                //                UIManager.put("nimbusRed", new Color(169, 46, 34));
                //                UIManager.put("nimbusSelectedText", Color.decode("#ff00ff"));
                UIManager.put("nimbusSelectionBackground", Color.decode("#465059"));
                //                UIManager.put("text", new Color(0, 0, 0));

                UIManager.put("nimbusSelection", Color.decode("#465059"));
                //                UIManager.put("Menu.background", Color.decode("#0066ff"));
                //                UIManager.put("Menu[Enabled+Selected].backgroundPainter", Color.BLUE);

                SwingUtilities.updateComponentTreeUI(comp);
                return;
            } catch (Exception e) {
                e.printStackTrace();/*from  w  w w .  j  a  va  2  s. com*/
            }
        }
    }
}

From source file:Main.java

private void changeTheLookAndFeel(int value) {
    try {/*from w  ww.j  a  va  2 s  .  c o  m*/
        UIManager.setLookAndFeel(looks[value].getClassName());
        SwingUtilities.updateComponentTreeUI(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:OAT.ui.util.UiUtil.java

public static void useCrossPlatformLookAndFeel(Component object) {
    String laf;/*from  w  ww  . j a  v  a 2s.c o  m*/
    boolean useNative = false;

    if (useNative) {
        laf = UIManager.getSystemLookAndFeelClassName();
    } else {
        laf = UIManager.getCrossPlatformLookAndFeelClassName();
    }

    try {
        UIManager.setLookAndFeel(laf);
        SwingUtilities.updateComponentTreeUI(object);
    } catch (Exception e) {
        System.err.println("Couldn't use the " + laf + "look and feel: " + e);
    }
}

From source file:CascadeDemo.java

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == m_newFrame)
        newFrame();/*from w w  w  .  j  av a2  s . co m*/
    else if (e.getSource() == m_UIBox) {
        m_UIBox.hidePopup(); // BUG WORKAROUND
        try {
            UIManager.setLookAndFeel(m_infos[m_UIBox.getSelectedIndex()].getClassName());
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception ex) {
            System.out.println("Could not load " + m_infos[m_UIBox.getSelectedIndex()].getClassName());
        }
    }
}

From source file:SimpleInternalFrameDemo.java

public void actionPerformed(ActionEvent e) {
    String lnfName = null;//  w  w  w.j a v a2  s .c  om
    if (e.getActionCommand().equals("Mac")) {
        lnfName = "com.apple.mrj.swing.MacLookAndFeel";
    } else if (e.getActionCommand().equals("Metal")) {
        lnfName = "javax.swing.plaf.metal.MetalLookAndFeel";
    } else if (e.getActionCommand().equals("Motif")) {
        lnfName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
    } else if (e.getActionCommand().equals("Windows")) {
        lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    } else {
        System.err.println("Unrecognized L&F request action: " + e.getActionCommand());
        return;
    }
    try {
        UIManager.setLookAndFeel(lnfName);
        SwingUtilities.updateComponentTreeUI(frame);
    } catch (UnsupportedLookAndFeelException ex1) {
        System.err.println("Unsupported LookAndFeel: " + lnfName);
    } catch (ClassNotFoundException ex2) {
        System.err.println("LookAndFeel class not found: " + lnfName);
    } catch (InstantiationException ex3) {
        System.err.println("Could not load LookAndFeel: " + lnfName);
    } catch (IllegalAccessException ex4) {
        System.err.println("Cannot use LookAndFeel: " + lnfName);
    }
}

From source file:com.alvermont.terraj.util.ui.LookAndFeelWatcher.java

/**
 * Process a look and feel changed event
 *
 * @param event The event that is being notified
 *///  w  w  w  . j  a  va 2 s  . com
public void handleLookAndFeelChangedEvent(LookAndFeelChangedEvent event) {
    SwingUtilities.updateComponentTreeUI(this.topLevel);
    this.topLevel.pack();
}