Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista. - Java Swing

Java examples for Swing:JPanel

Description

Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.

Demo Code

/*//from w  ww .  ja  v  a2  s .  c  om
 * 09/08/2005
 *
 * UIUtil.java - Utility methods for org.fife.ui classes.
 * Copyright (C) 2005 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */
//package com.java2s;

import java.awt.LayoutManager;

import javax.swing.JPanel;

public class Main {
    private static int nonOpaqueTabbedPaneComponents = -1;

    /**
     * Returns an opaque panel so we get the cool gradient effect on Windows
     * XP and Vista.
     *
     * @return A panel to add to a <code>JTabbedPane</code>.
     * @see #newTabbedPanePanel(LayoutManager)
     * @see #newTabbedPaneButton(String)
     */
    public static JPanel newTabbedPanePanel() {
        JPanel panel = new JPanel();
        if (getUseNonOpaqueTabbedPaneComponents())
            panel.setOpaque(false);
        return panel;
    }

    /**
     * Returns an opaque panel so we get the cool gradient effect on Windows
     * XP and Vista.
     *
     * @param layout The layout for the panel.
     * @return A panel to add to a <code>JTabbedPane</code>.
     * @see #newTabbedPanePanel()
     * @see #newTabbedPaneButton(String)
     */
    public static JPanel newTabbedPanePanel(LayoutManager layout) {
        JPanel panel = new JPanel(layout);
        if (getUseNonOpaqueTabbedPaneComponents())
            panel.setOpaque(false);
        return panel;
    }

    /**
     * Returns whether or not this operating system should use non-opaque
     * components in tabbed panes to show off, for example, a gradient effect.
     *
     * @return Whether or not non-opaque components should be used in tabbed
     *         panes.
     */
    static synchronized boolean getUseNonOpaqueTabbedPaneComponents() {

        if (nonOpaqueTabbedPaneComponents == -1) {

            // Check for Windows XP.
            String osname = System.getProperty("os.name");
            if (osname.toLowerCase().indexOf("windows") > -1) {
                String osver = System.getProperty("os.version");
                boolean isXPorVista = osver.startsWith("5.1")
                        || osver.startsWith("6.0");
                nonOpaqueTabbedPaneComponents = isXPorVista ? 1 : 0;
            } else {
                nonOpaqueTabbedPaneComponents = 0;
            }

        }

        return nonOpaqueTabbedPaneComponents == 1 ? true : false;

    }
}

Related Tutorials