Java Code Examples for javax.swing.UIManager#LookAndFeelInfo

The following examples show how to use javax.swing.UIManager#LookAndFeelInfo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingUtils.java    From RemoteSupportTool with Apache License 2.0 6 votes vote down vote up
public static void installLookAndFeel() {
    try {
        if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC) {
            // Always use system look & feel on Windows & Mac.
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } else {
            // Prefer Nimbus or Metal look & feel on other systems.
            UIManager.LookAndFeelInfo lnf = SwingUtils.getLookAndFeelInfo("Nimbus");
            if (lnf == null) lnf = SwingUtils.getLookAndFeelInfo("Metal");
            UIManager.setLookAndFeel((lnf != null) ?
                    lnf.getClassName() :
                    UIManager.getSystemLookAndFeelClassName());
        }
    } catch (Exception ex) {
        LOGGER.warn("Can't set look & feel!", ex);
    }
}
 
Example 2
Source File: Test7022041.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
    // try to test all installed Look and Feels
    for (UIManager.LookAndFeelInfo lookAndFeel : installedLookAndFeels) {
        String name = lookAndFeel.getName();
        System.out.println("Testing " + name);
        // Some Look and Feels work only when test is run in a GUI environment
        // (GTK+ LAF is an example)
        try {
            UIManager.setLookAndFeel(lookAndFeel.getClassName());
            checkTitleColor();
            System.out.println("    titleColor test ok");
            checkTitleFont();
            System.out.println("    titleFont test ok");
        }
        catch (UnsupportedLookAndFeelException e) {
            System.out.println("    Note: LookAndFeel " + name
                             + " is not supported on this configuration");
        }
    }
}
 
Example 3
Source File: Test7022041.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
    // try to test all installed Look and Feels
    for (UIManager.LookAndFeelInfo lookAndFeel : installedLookAndFeels) {
        String name = lookAndFeel.getName();
        System.out.println("Testing " + name);
        // Some Look and Feels work only when test is run in a GUI environment
        // (GTK+ LAF is an example)
        try {
            UIManager.setLookAndFeel(lookAndFeel.getClassName());
            checkTitleColor();
            System.out.println("    titleColor test ok");
            checkTitleFont();
            System.out.println("    titleFont test ok");
        }
        catch (UnsupportedLookAndFeelException e) {
            System.out.println("    Note: LookAndFeel " + name
                             + " is not supported on this configuration");
        }
    }
}
 
Example 4
Source File: Test7022041.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
    // try to test all installed Look and Feels
    for (UIManager.LookAndFeelInfo lookAndFeel : installedLookAndFeels) {
        String name = lookAndFeel.getName();
        System.out.println("Testing " + name);
        // Some Look and Feels work only when test is run in a GUI environment
        // (GTK+ LAF is an example)
        try {
            UIManager.setLookAndFeel(lookAndFeel.getClassName());
            checkTitleColor();
            System.out.println("    titleColor test ok");
            checkTitleFont();
            System.out.println("    titleFont test ok");
        }
        catch (UnsupportedLookAndFeelException e) {
            System.out.println("    Note: LookAndFeel " + name
                             + " is not supported on this configuration");
        }
    }
}
 
Example 5
Source File: JComboBoxPopupLocation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    robot = new Robot();
    robot.setAutoDelay(100);
    robot.setAutoWaitForIdle(true);
    GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] sds = ge.getScreenDevices();
    UIManager.LookAndFeelInfo[] lookAndFeelArray =
            UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        System.setProperty(PROPERTY_NAME, "true");
        step(sds, lookAndFeelItem);
        if (lookAndFeelItem.getClassName().contains("Aqua")) {
            System.setProperty(PROPERTY_NAME, "false");
            step(sds, lookAndFeelItem);
        }
    }
}
 
Example 6
Source File: TestJInternalFrameMaximize.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    UIManager.LookAndFeelInfo[] lookAndFeelArray
            = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        String lookAndFeelString = lookAndFeelItem.getClassName();
        if (tryLookAndFeel(lookAndFeelString)) {
            createUI();
            robot.waitForIdle();
            executeTest();
            robot.delay(1000);
        }
    }
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 7
Source File: MisplacedBorder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
        SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
        SwingUtilities.invokeAndWait(new MisplacedBorder());
    }
    System.out.println("Test passed");
}
 
Example 8
Source File: bug6421058.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
    try {
        UIManager.setLookAndFeel(laf.getClassName());
    } catch (ClassNotFoundException | InstantiationException |
            UnsupportedLookAndFeelException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: DefaultsDisplay.java    From littleluck with Apache License 2.0 5 votes vote down vote up
protected JComponent createLookAndFeelControl() {
    JPanel panel = new JPanel();
    
    JLabel label = new JLabel("Current Look and Feel");
    lookAndFeelComboBox = new JComboBox();
    label.setLabelFor(lookAndFeelComboBox);
    panel.add(label);
    panel.add(lookAndFeelComboBox);
    
    // Look for toolkit look and feels first
    UIManager.LookAndFeelInfo lookAndFeelInfos[] = UIManager.getInstalledLookAndFeels();
    lookAndFeelsMap = new HashMap<String,String>();
    for(UIManager.LookAndFeelInfo info : lookAndFeelInfos) {
        String name = info.getName();
        // workaround for problem where Info and name property don't match on OS X
        if (name.equals("Mac OS X")) {
            name = OSXLookAndFeelName;
        }
        // workaround for bug where Nimbus classname is incorrect
        lookAndFeelsMap.put(name, name.equals("Nimbus")? 
            "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" :
                      info.getClassName());
        lookAndFeelComboBox.addItem(name);
    }
    lookAndFeelComboBox.setSelectedItem(UIManager.getLookAndFeel().getName());
    lookAndFeelComboBox.addActionListener(new ChangeLookAndFeelAction());
    
    return panel;
}
 
Example 10
Source File: LaFHelper.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private static boolean trySetNimbusLookAndFeel() {
    try {
        for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
        return true;
    } catch (Exception ex) {
        System.err.println(ex);
    }
    return false;
}
 
Example 11
Source File: ScrollableTabbedPaneTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    robot.delay(1000);
    UIManager.LookAndFeelInfo[] lookAndFeelArray
            = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        executeCase(lookAndFeelItem.getClassName(),
                    lookAndFeelItem.getName());
    }
    if (!"".equals(errorString)) {
        throw new RuntimeException("Error Log:\n" + errorString);
    }
}
 
Example 12
Source File: MisplacedBorder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
    try {
        UIManager.setLookAndFeel(laf.getClassName());
        System.out.println("LookAndFeel: " + laf.getClassName());
    } catch (ClassNotFoundException | InstantiationException |
            UnsupportedLookAndFeelException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source File: Test4319113.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void show(Window window) {
    JButton jButton = new JButton("Show ColorChooser");
    jButton.setActionCommand("Show ColorChooser");
    jButton.addActionListener(this);
    this.cbPlaf = new JComboBox<UIManager.LookAndFeelInfo>(UIManager.getInstalledLookAndFeels());
    this.cbPlaf.addItemListener(new ItemListener(){

        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            if (itemEvent.getStateChange() == 1) {
                SwingUtilities.invokeLater(new Runnable(){

                    @Override
                    public void run() {
                        UIManager.LookAndFeelInfo lookAndFeelInfo = (UIManager.LookAndFeelInfo)Test4319113.this.cbPlaf.getSelectedItem();
                        try {
                            UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
                            Frame[] arrframe = Frame.getFrames();
                            int n = arrframe.length;
                            while (--n >= 0) {
                                Test4319113.updateWindowTreeUI(arrframe[n]);
                            }
                        }
                        catch (Exception var2_3) {
                            System.err.println("Exception while changing L&F!");
                        }
                    }
                });
            }
        }

    });
    window.add(this.cbPlaf);
    window.add(jButton);
    window.pack();
    window.setVisible(true);
}
 
Example 14
Source File: JInternalFrameIconTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    robot.delay(2000);
    UIManager.LookAndFeelInfo[] lookAndFeelArray
            = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        executeCase(lookAndFeelItem.getClassName());
    }
    if (!"".equals(errorString)) {
        throw new RuntimeException("Error Log:\n" + errorString);
    }

}
 
Example 15
Source File: bug6190373.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
    try {
        UIManager.setLookAndFeel(laf.getClassName());
        System.out.println("LookAndFeel: " + laf.getClassName());
    } catch (ClassNotFoundException | InstantiationException |
            UnsupportedLookAndFeelException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 16
Source File: FileFilterDescription.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void setLookAndFeel(final UIManager.LookAndFeelInfo info) {
    try {
        UIManager.setLookAndFeel(info.getClassName());
    } catch (ClassNotFoundException | InstantiationException |
            UnsupportedLookAndFeelException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Source File: Test8015300.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo info : array) {
        UIManager.setLookAndFeel(info.getClassName());
        System.err.println("L&F: " + info.getName());
        invokeAndWait(new Runnable() {
            @Override
            public void run() {
                combo = new JComboBox<>(ITEMS);
                combo.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent event) {
                        if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) {
                            ComboBoxEditor editor = combo.getEditor();
                            Object component = editor.getEditorComponent();
                            if (component instanceof JTextField) {
                                JTextField text = (JTextField) component;
                                boolean selected = null != text.getSelectedText();

                                StringBuilder sb = new StringBuilder();
                                sb.append(" - ").append(combo.getSelectedIndex());
                                sb.append(": ").append(event.getItem());
                                if (selected) {
                                    sb.append("; selected");
                                }
                                System.err.println(sb);
                                if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) {
                                    throw new Error("unexpected state of text selection");
                                }
                            }
                        }
                    }
                });
                JFrame frame = new JFrame(getClass().getSimpleName());
                frame.add(combo);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                frame.setVisible(true);
            }
        });
        for (int i = 0; i < ITEMS.length; ++i) {
            select(i, true);
            select(1, false);
        }
        invokeAndWait(new Runnable() {
            @Override
            public void run() {
                windowForComponent(combo).dispose();
            }
        });
    }
}
 
Example 18
Source File: ProgressBarMemoryLeakTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
  for ( UIManager.LookAndFeelInfo installedLookAndFeel : installedLookAndFeels ) {
    executeTestCase(installedLookAndFeel.getClassName());
  }
}
 
Example 19
Source File: Test8015300.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo info : array) {
        UIManager.setLookAndFeel(info.getClassName());
        System.err.println("L&F: " + info.getName());
        invokeAndWait(new Runnable() {
            @Override
            public void run() {
                combo = new JComboBox<>(ITEMS);
                combo.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent event) {
                        if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) {
                            ComboBoxEditor editor = combo.getEditor();
                            Object component = editor.getEditorComponent();
                            if (component instanceof JTextField) {
                                JTextField text = (JTextField) component;
                                boolean selected = null != text.getSelectedText();

                                StringBuilder sb = new StringBuilder();
                                sb.append(" - ").append(combo.getSelectedIndex());
                                sb.append(": ").append(event.getItem());
                                if (selected) {
                                    sb.append("; selected");
                                }
                                System.err.println(sb);
                                if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) {
                                    throw new Error("unexpected state of text selection");
                                }
                            }
                        }
                    }
                });
                JFrame frame = new JFrame(getClass().getSimpleName());
                frame.add(combo);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                frame.setVisible(true);
            }
        });
        for (int i = 0; i < ITEMS.length; ++i) {
            select(i, true);
            select(1, false);
        }
        invokeAndWait(new Runnable() {
            @Override
            public void run() {
                windowForComponent(combo).dispose();
            }
        });
    }
}
 
Example 20
Source File: Test8015300.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo info : array) {
        UIManager.setLookAndFeel(info.getClassName());
        System.err.println("L&F: " + info.getName());
        invokeAndWait(new Runnable() {
            @Override
            public void run() {
                combo = new JComboBox<>(ITEMS);
                combo.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent event) {
                        if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) {
                            ComboBoxEditor editor = combo.getEditor();
                            Object component = editor.getEditorComponent();
                            if (component instanceof JTextField) {
                                JTextField text = (JTextField) component;
                                boolean selected = null != text.getSelectedText();

                                StringBuilder sb = new StringBuilder();
                                sb.append(" - ").append(combo.getSelectedIndex());
                                sb.append(": ").append(event.getItem());
                                if (selected) {
                                    sb.append("; selected");
                                }
                                System.err.println(sb);
                                if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) {
                                    throw new Error("unexpected state of text selection");
                                }
                            }
                        }
                    }
                });
                JFrame frame = new JFrame(getClass().getSimpleName());
                frame.add(combo);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                frame.setVisible(true);
            }
        });
        for (int i = 0; i < ITEMS.length; ++i) {
            select(i, true);
            select(1, false);
        }
        invokeAndWait(new Runnable() {
            @Override
            public void run() {
                windowForComponent(combo).dispose();
            }
        });
    }
}