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

The following examples show how to use javax.swing.UIManager#setLookAndFeel() . 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: Metalworks.java    From openjdk-8-source with GNU General Public License v2.0 7 votes vote down vote up
public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame.setDefaultLookAndFeelDecorated(true);
    Toolkit.getDefaultToolkit().setDynamicLayout(true);
    System.setProperty("sun.awt.noerasebackground", "true");
    try {
        UIManager.setLookAndFeel(new MetalLookAndFeel());
    } catch (UnsupportedLookAndFeelException e) {
        System.out.println(
                "Metal Look & Feel not supported on this platform. \n"
                + "Program Terminated");
        System.exit(0);
    }
    JFrame frame = new MetalworksFrame();
    frame.setVisible(true);
}
 
Example 2
Source File: Test7022041.java    From openjdk-jdk8u 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: bug8020708.java    From jdk8u60 with GNU General Public License v2.0 6 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 4
Source File: HarcletFrame.java    From IrScrutinizer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates new form
 * @param panel
 * @param exitOnClose
 * @param lafClassName
 */
public HarcletFrame(HarcPanel panel, boolean exitOnClose, String lafClassName) {
    try {
        if (lafClassName != null)
            UIManager.setLookAndFeel(lafClassName);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
        //error(ex);
    }
    this.exitOnClose = exitOnClose;
    harclet = panel;
    initComponents();
    super.setTitle(harclet.getProgName());

    super.setIconImage((new ImageIcon(HarcletFrame.class.getResource(harclet.getIconPath()))).getImage());
    super.setResizable(false);

    if (exitOnClose) {
        super.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    }
}
 
Example 5
Source File: BsafTest.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void startup ()
{
    String lafName =
            LookUtils.IS_OS_WINDOWS_XP
            ? com.jgoodies.looks.Options.getCrossPlatformLookAndFeelClassName()
            : com.jgoodies.looks.Options.getSystemLookAndFeelClassName();

    try {
        UIManager.setLookAndFeel(lafName);
    } catch (Exception e) {
        System.err.println("Can't set look & feel:" + e);
    }


    JFrame frame = getMainFrame();
    frame.setJMenuBar(buildMenuBar());
    frame.setContentPane(buildContentPane());
    frame.setSize(600, 400);
    frame.setTitle("BSAF Test");
    show(frame);
}
 
Example 6
Source File: TableExample.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String s[]) {
    // 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(TableExample.class.getName()).log(Level.SEVERE,
                "Failed to apply Nimbus look and feel", ex);
    }

    new TableExample();
}
 
Example 7
Source File: DimensionEncapsulation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void setLookAndFeel(final LookAndFeelInfo laf) {
    try {
        UIManager.setLookAndFeel(laf.getClassName());
        System.out.println("LookAndFeel: " + laf.getClassName());
    } catch (ClassNotFoundException | InstantiationException |
            UnsupportedLookAndFeelException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: SilenceOfDeprecatedMenuBar.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 9
Source File: GithubPanel.java    From MakeLobbiesGreatAgain with MIT License 5 votes vote down vote up
/**
 * Creates the new Panel and parses the supplied HTML.  <br>
 * <b> Supported Github Markdown: </b><i> Lists (unordered), Links, Images, Bold ('**' and '__'), Strikethrough, & Italics.  </i>
 *
 * @param currentVersion The version of the Jar currently running.
 */
public GithubPanel(double currentVersion) {
	this.version = currentVersion;

	setTitle("MLGA Update");
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		parseReleases();
	} catch (Exception e1) {
		e1.printStackTrace();
	}
	if (updates <= 0) {
		return;
	}
	ed = new JEditorPane("text/html", html);
	ed.setEditable(false);
	ed.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
	ed.setFont(new Font("Helvetica", 0, 12));

	ed.addHyperlinkListener(he -> {
		// Listen to link clicks and open them in the browser.
		if (he.getEventType() == EventType.ACTIVATED && Desktop.isDesktopSupported()) {
			try {
				Desktop.getDesktop().browse(he.getURL().toURI());
				System.exit(0);
			} catch (IOException | URISyntaxException e) {
				e.printStackTrace();
			}
		}
	});
	final JScrollPane scrollPane = new JScrollPane(ed);
	scrollPane.setPreferredSize(new Dimension(1100, 300));
	add(scrollPane);
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	pack();
	setLocationRelativeTo(null);
}
 
Example 10
Source File: Test6707406.java    From jdk8u60 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 11
Source File: AxisRangeControlTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws ClassNotFoundException, UnsupportedLookAndFeelException, IllegalAccessException, InstantiationException {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    final JPanel axesPanel = new JPanel(new GridLayout(-1, 1));
    axesPanel.add(new AxisRangeControl("X-Axis").getPanel());
    axesPanel.add(new AxisRangeControl("Y-Axis").getPanel());

    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(axesPanel);
    frame.pack();
    frame.setVisible(true);
}
 
Example 12
Source File: JFileChooserOrientation.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean tryLookAndFeel(String lookAndFeelString)
        throws Exception {
    try {
        UIManager.setLookAndFeel(
                lookAndFeelString);
    } catch (UnsupportedLookAndFeelException
            | ClassNotFoundException
            | InstantiationException
            | IllegalAccessException e) {
        return false;
    }
    return true;
}
 
Example 13
Source File: Test6963870.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    } catch (Exception e) {
        System.out.println("GTKLookAndFeel cannot be set, skipping this test");
        return;
    }

    SwingUtilities.invokeAndWait(new Test6963870());
}
 
Example 14
Source File: bug8033069NoScrollBar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected static void iterateLookAndFeels(final bug8033069NoScrollBar 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: bug8002077.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 {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            runTest();
            break;
        }
    }
}
 
Example 16
Source File: Test6199676.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example 17
Source File: ColorCustomizationTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    nimbus = new NimbusLookAndFeel();
    try {
        UIManager.setLookAndFeel(nimbus);
    } catch (UnsupportedLookAndFeelException e) {
        throw new Error("Unable to set Nimbus LAF");
    }
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            new ColorCustomizationTest().test();
        }
    });
}
 
Example 18
Source File: MisplacedBorder.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 19
Source File: LSDPatcher.java    From lsdpatch with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    new LSDPatcher();
}
 
Example 20
Source File: Test8015926.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
    SwingUtilities.invokeAndWait(new Test8015926());
    Thread.sleep(1000L);
}