Java Code Examples for javax.swing.UIManager#getInstalledLookAndFeels()

The following examples show how to use javax.swing.UIManager#getInstalledLookAndFeels() . 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: TableExample2.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 5) {
        System.err.println("Needs database parameters eg. ...");
        System.err.println(
                "java TableExample2 \"jdbc:derby://localhost:1527/sample\" "
                + "org.apache.derby.jdbc.ClientDriver app app "
                + "\"select * from app.customer\"");
        return;
    }

    // Trying to set Nimbus look and feel
    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(TableExample2.class.getName()).log(Level.SEVERE,
                "Failed to apply Nimbus look and feel", ex);
    }

    new TableExample2(args[0], args[1], args[2], args[3], args[4]);
}
 
Example 2
Source File: GUI.java    From allsummarizer with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            System.out.println(info.getClassName());
		            break;
		        }
		    }
		} catch (Exception e) {
		    // If Nimbus is not available, you can set the GUI to another look and feel.
		}
	
	new GUI();
}
 
Example 3
Source File: Test7022041.java    From TencentKona-8 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: NimbusGlueTest.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();
            performTest();
            robot.waitForIdle();
        }
    }
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 5
Source File: bug8080628.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest() {
    try {
        LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
        for (LookAndFeelInfo info : lafInfo) {
            UIManager.setLookAndFeel(info.getClassName());

            for (Locale locale : LOCALES) {
                for (String key : MNEMONIC_KEYS) {
                    int mnemonic = SwingUtilities2.getUIDefaultsInt(key, locale);
                    if (mnemonic != 0) {
                        throw new RuntimeException("No mnemonic expected (" + mnemonic + ") " +
                                "for '" + key + "' " +
                                "in locale '" + locale + "' " +
                                "in Look-and-Feel '"
                                    + UIManager.getLookAndFeel().getClass().getName() + "'");
                    }
                }
            }
        }
        System.out.println("Test passed");
    } catch (Exception e) {
        exception = e;
    }
}
 
Example 6
Source File: Test7163696.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void test() throws Exception {
    Robot robot = new Robot();
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        UIManager.setLookAndFeel(info.getClassName());

        SwingUtilities.invokeAndWait(this);
        robot.waitForIdle(); // after creation
        Thread.sleep(1000);

        Point point = this.bar.getLocation();
        SwingUtilities.convertPointToScreen(point, this.bar);
        point.x += this.bar.getWidth() >> 2;
        point.y += this.bar.getHeight() >> 1;
        robot.mouseMove(point.x, point.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        robot.waitForIdle(); // before validation
        Thread.sleep(1000);
        SwingUtilities.invokeAndWait(this);

        if (this.bar != null) {
            this.bar = null; // allows to reuse the instance
            if (AUTO) { // error reporting only for automatic testing
                throw new Error("TEST FAILED");
            }
        }
    }
}
 
Example 7
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 8
Source File: Main.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static void setUpUI(String ui) {
    try {
        for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if (ui.equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                if (ui.equals("Nimbus")) {
                    tweakNimbusUI();
                }
                break;
            }
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 9
Source File: Test6707406.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    test();
    for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
        System.out.println(laf.getName());
        UIManager.setLookAndFeel(laf.getClassName());
        test();
    }
}
 
Example 10
Source File: bug8136998.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected static void iterateLookAndFeels(final bug8136998 test) throws Exception {
    LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for (LookAndFeelInfo info : lafInfo) {
        try {
            UIManager.setLookAndFeel(info.getClassName());
            System.out.println("Look and Feel: " + info.getClassName());
            test.runTest();
        } catch (UnsupportedLookAndFeelException e) {
            System.out.println("Skipping unsupported LaF: " + info);
        }
    }
}
 
Example 11
Source File: bug8020708.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static final boolean installLookAndFeel(String lafName) throws Exception {
    UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo info : infos) {
        if (info.getClassName().contains(lafName)) {
            UIManager.setLookAndFeel(info.getClassName());
            return true;
        }
    }
    return false;
}
 
Example 12
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 13
Source File: Test6707406.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    test();
    for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
        System.out.println(laf.getName());
        UIManager.setLookAndFeel(laf.getClassName());
        test();
    }
}
 
Example 14
Source File: bug8136998.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected static void iterateLookAndFeels(final bug8136998 test) throws Exception {
    LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for (LookAndFeelInfo info : lafInfo) {
        try {
            UIManager.setLookAndFeel(info.getClassName());
            System.out.println("Look and Feel: " + info.getClassName());
            test.runTest();
        } catch (UnsupportedLookAndFeelException e) {
            System.out.println("Skipping unsupported LaF: " + info);
        }
    }
}
 
Example 15
Source File: LookAndFeelPlugin.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ActionDescriptor[] getActionDescriptors() {
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    ActionDescriptor[] res = new ActionDescriptor[infos.length];
    final LookAndFeel laf = UIManager.getLookAndFeel();
    for (int i = 0; i < infos.length; i++) {
        final LookAndFeelInfo info = infos[i];
        ActionDescriptor ad = new ActionDescriptor();

        ad.setActionLevel(ActionLevel.GLOBAL);
        ad.setButtonGroup("LookAndFeel");
        ad.setMenu("Windows/LookAndFeel");
        ad.setSelective(true);

        AbstractAction action = new AbstractAction() {
            /**
             *
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                Options.setString("LookAndFeel", info.getClassName());
                System.setProperty("AnywayExit", Boolean.TRUE.toString());
                JOptionPane
                        .showMessageDialog(
                                framework.getMainFrame(),
                                GlobalResourcesManager
                                        .getString("LookAndFeelWillApplyAfterProgramReboot"));
            }
        };

        action.putValue(Action.SELECTED_KEY, (info.getClassName()
                .equals(laf.getClass().getName())));
        action.putValue(Action.ACTION_COMMAND_KEY, info.getName());
        ad.setAction(action);

        res[i] = ad;
    }
    return res;
}
 
Example 16
Source File: Test8013442.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    if (this.infos == null) {
        this.infos = UIManager.getInstalledLookAndFeels();
        Thread.currentThread().setUncaughtExceptionHandler(this);
    }
    if (this.infos.length == this.index) {
        LATCH.countDown(); // release main thread
    } else if (this.chooser == null) {
        // change LaF before creation of Swing components
        LookAndFeelInfo info = this.infos[this.index];
        System.out.println(info.getName());
        try {
            UIManager.setLookAndFeel(info.getClassName());
        }
        catch (Exception exception) {
            throw new Error("could not change look and feel", exception);
        }
        // create and show new file chooser
        JFrame frame = new JFrame(getClass().getSimpleName());
        frame.add(this.chooser = new JFileChooser());
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        SwingUtilities.invokeLater(this);
    }
    else {
        int count = this.chooser.getChoosableFileFilters().length;
        System.out.println("count = " + count + "; " + this.chooser.isAcceptAllFileFilterUsed());
        if (count == 0) {
            if (null != this.chooser.getFileFilter()) {
                throw new Error("file filter is selected");
            }
            // close window and stop testing file chooser for current LaF
            SwingUtilities.getWindowAncestor(this.chooser).dispose();
            this.chooser = null;
            this.index++;
        } else {
            if (null == this.chooser.getFileFilter()) {
                throw new Error("file filter is not selected");
            }
            if (count == 2) {
                // remove default file filter
                this.chooser.setAcceptAllFileFilterUsed(false);
            } else if (this.chooser.isAcceptAllFileFilterUsed()) {
                // remove add file filter
                this.chooser.addChoosableFileFilter(this);
            } else {
                // remove custom file filter
                this.chooser.removeChoosableFileFilter(this);
            }
        }
        SwingUtilities.invokeLater(this);
    }
}
 
Example 17
Source File: Test8015300.java    From jdk8u-jdk 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: Test8013442.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    if (this.infos == null) {
        this.infos = UIManager.getInstalledLookAndFeels();
        Thread.currentThread().setUncaughtExceptionHandler(this);
    }
    if (this.infos.length == this.index) {
        LATCH.countDown(); // release main thread
    } else if (this.chooser == null) {
        // change LaF before creation of Swing components
        LookAndFeelInfo info = this.infos[this.index];
        System.out.println(info.getName());
        try {
            UIManager.setLookAndFeel(info.getClassName());
        }
        catch (Exception exception) {
            throw new Error("could not change look and feel", exception);
        }
        // create and show new file chooser
        JFrame frame = new JFrame(getClass().getSimpleName());
        frame.add(this.chooser = new JFileChooser());
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        SwingUtilities.invokeLater(this);
    }
    else {
        int count = this.chooser.getChoosableFileFilters().length;
        System.out.println("count = " + count + "; " + this.chooser.isAcceptAllFileFilterUsed());
        if (count == 0) {
            if (null != this.chooser.getFileFilter()) {
                throw new Error("file filter is selected");
            }
            // close window and stop testing file chooser for current LaF
            SwingUtilities.getWindowAncestor(this.chooser).dispose();
            this.chooser = null;
            this.index++;
        } else {
            if (null == this.chooser.getFileFilter()) {
                throw new Error("file filter is not selected");
            }
            if (count == 2) {
                // remove default file filter
                this.chooser.setAcceptAllFileFilterUsed(false);
            } else if (this.chooser.isAcceptAllFileFilterUsed()) {
                // remove add file filter
                this.chooser.addChoosableFileFilter(this);
            } else {
                // remove custom file filter
                this.chooser.removeChoosableFileFilter(this);
            }
        }
        SwingUtilities.invokeLater(this);
    }
}
 
Example 19
Source File: Test6657026.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    SunToolkit.createNewAppContext();
    if (UIManager.getInstalledLookAndFeels().length == 0) {
        throw new Error("shared look&feels");
    }
}
 
Example 20
Source File: Test6657026.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    SunToolkit.createNewAppContext();
    if (UIManager.getInstalledLookAndFeels().length == 0) {
        throw new Error("shared look&feels");
    }
}