Java JMenu applyDefaultProperties(final JMenu comp)

Here you can find the source of applyDefaultProperties(final JMenu comp)

Description

Sets default background and foreground color as well as a default font for the specified component.

License

Open Source License

Parameter

Parameter Description
comp Component to set default properties for. Can be <code>null</code>.

Declaration

public static void applyDefaultProperties(final JMenu comp) 

Method Source Code


//package com.java2s;
/*/*  ww w. j  ava  2s.  co  m*/
 * ------------------------------------------------------------------
 * This source code, its documentation and all appendant files
 * are protected by copyright law. All rights reserved.
 *
 * Copyright (C) 2012
 * Novartis Institutes for BioMedical Research
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, Version 3, as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses>.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  KNIME interoperates with ECLIPSE solely via ECLIPSE's plug-in APIs.
 *  Hence, KNIME and ECLIPSE are both independent programs and are not
 *  derived from each other. Should, however, the interpretation of the
 *  GNU GPL Version 3 ("License") under any applicable laws result in
 *  KNIME and ECLIPSE being a combined program, KNIME GMBH herewith grants
 *  you the additional permission to use and propagate KNIME together with
 *  ECLIPSE with only the license terms in place for ECLIPSE applying to
 *  ECLIPSE and the GNU GPL Version 3 applying for KNIME, provided the
 *  license terms of ECLIPSE themselves allow for the respective use and
 *  propagation of ECLIPSE together with KNIME.
 *
 *  Additional permission relating to nodes for KNIME that extend the Node
 *  Extension (and in particular that are based on subclasses of NodeModel,
 *  NodeDialog, and NodeView) and that only interoperate with KNIME through
 *  standard APIs ("Nodes"):
 *  Nodes are deemed to be separate and independent programs and to not be
 *  covered works.  Notwithstanding anything to the contrary in the
 *  License, the License does not apply to Nodes, you are not required to
 *  license Nodes under the License, and you are granted a license to
 *  prepare and propagate Nodes, in each case even if such Nodes are
 *  propagated with or for interoperation with KNIME.  The owner of a Node
 *  may freely choose the license terms applicable to such Node, including
 *  when such Node is propagated with or for interoperation with KNIME.
 * ---------------------------------------------------------------------
 */

import java.awt.Button;

import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;

import java.awt.Dialog;

import java.awt.Font;

import java.awt.Label;
import java.awt.List;
import java.awt.Panel;

import java.awt.ScrollPane;
import java.awt.Scrollbar;
import java.awt.TextArea;
import java.awt.TextComponent;
import java.awt.TextField;

import java.awt.Window;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.UIManager;

import javax.swing.text.JTextComponent;

public class Main {
    /**
     * Defines the default fall back color for backgrounds. The default is
     * white.
     */
    private static final Color DEFAULT_BACKGROUND = Color.white;
    /**
     * Defines the default fall back color for foregrounds. The default is
     * black.
     */
    private static final Color DEFAULT_FOREGROUND = Color.black;
    /**
     * Defines the default fall back font to be used when no other font is
     * available. The default is Font("Helvetica", Font.PLAIN, 12).
     */
    private static Font g_defaultFont = null;

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Button comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Button.background", // $NON-NLS-1$
                "Button.foreground", // $NON-NLS-1$
                "Button.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JButton comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Button.background", // $NON-NLS-1$
                "Button.foreground", // $NON-NLS-1$
                "Button.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Choice comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "ComboBox.background", // $NON-NLS-1$
                "ComboBox.foreground", // $NON-NLS-1$
                "ComboBox.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JComboBox<?> comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "ComboBox.background", // $NON-NLS-1$
                "ComboBox.foreground", // $NON-NLS-1$
                "ComboBox.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Label comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Label.background", // $NON-NLS-1$
                "Label.foreground", // $NON-NLS-1$
                "Label.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JLabel comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Label.background", // $NON-NLS-1$
                "Label.foreground", // $NON-NLS-1$
                "Label.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final List comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "List.background", // $NON-NLS-1$
                "List.foreground", // $NON-NLS-1$
                "List.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JList<?> comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "List.background", // $NON-NLS-1$
                "List.foreground", // $NON-NLS-1$
                "List.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JMenuItem comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "MenuItem.background", // $NON-NLS-1$
                "MenuItem.foreground", // $NON-NLS-1$
                "MenuItem.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JMenu comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Menu.background", // $NON-NLS-1$
                "Menu.foreground", // $NON-NLS-1$
                "Menu.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JPopupMenu comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "PopupMenu.background", // $NON-NLS-1$
                "PopupMenu.foreground", // $NON-NLS-1$
                "PopupMenu.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JMenuBar comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "MenuBar.background", // $NON-NLS-1$
                "MenuBar.foreground", // $NON-NLS-1$
                "MenuBar.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JOptionPane comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "OptionPane.background", // $NON-NLS-1$
                "OptionPane.foreground", // $NON-NLS-1$
                "OptionPane.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Checkbox comp) {
        if (comp == null) {
            return;
        }

        if (comp.getCheckboxGroup() == null) {
            applyProperties(comp, "CheckBox.background", // $NON-NLS-1$
                    "CheckBox.foreground", // $NON-NLS-1$
                    "CheckBox.font"); // $NON-NLS-1$
        } else {
            // Checkbox is in group
            applyProperties(comp, "RadioButton.background", // $NON-NLS-1$
                    "RadioButton.foreground", // $NON-NLS-1$
                    "RadioButton.font"); // $NON-NLS-1$
        }
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JCheckBox comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "CheckBox.background", // $NON-NLS-1$
                "CheckBox.foreground", // $NON-NLS-1$
                "CheckBox.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JRadioButton comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "RadioButton.background", // $NON-NLS-1$
                "RadioButton.foreground", // $NON-NLS-1$
                "RadioButton.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Scrollbar comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "ScrollBar.background", // $NON-NLS-1$
                "ScrollBar.foreground", // $NON-NLS-1$
                null); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JScrollBar comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "ScrollBar.background", // $NON-NLS-1$
                "ScrollBar.foreground", // $NON-NLS-1$
                null);
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final ScrollPane comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "ScrollPane.background", // $NON-NLS-1$
                "ScrollPane.foreground", // $NON-NLS-1$
                "ScrollPane.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JScrollPane comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "ScrollPane.background", // $NON-NLS-1$
                "ScrollPane.foreground", // $NON-NLS-1$
                "ScrollPane.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JSeparator comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Separator.background", // $NON-NLS-1$
                "Separator.foreground", // $NON-NLS-1$
                "Separator.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JSplitPane comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "SplitPane.background", // $NON-NLS-1$
                null, null);
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JTabbedPane comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "TabbedPane.background", // $NON-NLS-1$
                "TabbedPane.foreground", // $NON-NLS-1$
                "TabbedPane.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JTable comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Table.background", // $NON-NLS-1$
                "Table.foreground", // $NON-NLS-1$
                "Table.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final TextArea comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "TextArea.background", // $NON-NLS-1$
                "TextArea.foreground", // $NON-NLS-1$
                "TextArea.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JTextArea comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "TextArea.background", // $NON-NLS-1$
                "TextArea.foreground", // $NON-NLS-1$
                "TextArea.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final TextField comp) {
        if (comp == null) {
            return;
        }

        if (comp.getEchoChar() != (char) 0) {
            applyProperties(comp, "PasswordField.background", // $NON-NLS-1$
                    "PasswordField.foreground", // $NON-NLS-1$
                    "PasswordField.font"); // $NON-NLS-1$
        } else {
            // Normal text field
            applyProperties(comp, "TextField.background", // $NON-NLS-1$
                    "TextField.foreground", // $NON-NLS-1$
                    "TextField.font"); // $NON-NLS-1$
        }
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JTextField comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "TextField.background", // $NON-NLS-1$
                "TextField.foreground", // $NON-NLS-1$
                "TextField.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JPasswordField comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "PasswordField.background", // $NON-NLS-1$
                "PasswordField.foreground", // $NON-NLS-1$
                "PasswordField.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JTree comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Tree.background", // $NON-NLS-1$
                "Tree.foreground", // $NON-NLS-1$
                "Tree.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Panel comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Panel.background", // $NON-NLS-1$
                "Panel.foreground", // $NON-NLS-1$
                "Panel.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JPanel comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "Panel.background", // $NON-NLS-1$
                "Panel.foreground", // $NON-NLS-1$
                "Panel.font"); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Window comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "window", // $NON-NLS-1$
                "windowText", // $NON-NLS-1$
                null); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Dialog comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "control", // $NON-NLS-1$
                "controlText", // $NON-NLS-1$
                null); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JDialog comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "control", // $NON-NLS-1$
                "controlText", // $NON-NLS-1$
                null); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final TextComponent comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "text", // $NON-NLS-1$
                "textText", // $NON-NLS-1$
                null); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component. It uses values defined as UIManager
     * properties.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final JTextComponent comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "text", // $NON-NLS-1$
                "textText", // $NON-NLS-1$
                null); // $NON-NLS-1$
    }

    /**
     * Sets default background and foreground color as well as a default font
     * for the specified component.
     * 
     * @param comp
     *            Component to set default properties for. Can be
     *            <code>null</code>.
     */
    public static void applyDefaultProperties(final Component comp) {
        if (comp == null) {
            return;
        }

        applyProperties(comp, "control", // $NON-NLS-1$
                "controlText", // $NON-NLS-1$
                null);
    }

    /**
     * Sets background and foreground color and a font for the specified
     * component.
     * 
     * @param comp
     *            Component to set properties for.
     * @param colBack
     *            Background color. Can be <code>null</code> to use parent color
     *            (not suggested due to differences between Java VMs).
     * @param colFore
     *            Foreground color. Can be <code>null</code> to use parent color
     *            (not suggested due to differences between Java VMs).
     * @param font
     *            Font. Can be <code>null</code> to use parent font (not
     *            suggested due to differences between Java VMs).
     */
    public static void applyProperties(final Component comp, final Color colBack, final Color colFore,
            final Font font) {
        if (comp != null) {
            comp.setBackground(colBack);
            comp.setForeground(colFore);
            comp.setFont(font);
        }
    }

    /**
     * Sets background and foreground color and a font for the specified
     * component.
     * 
     * @param comp
     *            Component to set properties for. If <code>
     * null</code> nothing happens.
     * @param strKeyBackground
     *            Key for background color defined in
     *            <code>javax.swing.UIManager</code>. If it is <code>null</code>
     *            or not found first the key "control" will be tried, and if
     *            still <code>null</code>, a "fallback" color will be taken.
     * @param strKeyForeground
     *            Key for background color defined in
     *            <code>javax.swing.UIManager</code>. If it is <code>null</code>
     *            or not found first the key "textText" will be tried, and if
     *            still <code>null</code>, a "fallback" color will be taken.
     * @param strKeyFont
     *            Key for font defined in <code>
     * javax.swing.UIManager</code>. If it is <code>null</code> or not found
     *            first the key "Label.font" will be tried, and if still
     *            <code>null</code>, a "fallback" font will be taken.
     */
    public static void applyProperties(final Component comp, final String strKeyBackground,
            final String strKeyForeground, final String strKeyFont) {
        if (comp != null) {
            Color colBack = null;
            Color colFore = null;
            Font font = null;

            if (strKeyBackground != null) {
                colBack = UIManager.getColor(strKeyBackground);
            }

            if (strKeyForeground != null) {
                colFore = UIManager.getColor(strKeyForeground);
            }

            if (strKeyFont != null) {
                font = UIManager.getFont(strKeyFont);
            }

            if (colBack == null) {
                colBack = UIManager.getColor("control"); // $NON-NLS-1$

                if (colBack == null) {
                    colBack = DEFAULT_BACKGROUND; // Fall back default
                }
            }

            if (colFore == null) {
                colFore = UIManager.getColor("controlText"); // $NON-NLS-1$

                if (colFore == null) {
                    colFore = DEFAULT_FOREGROUND; // Fall back default
                }
            }

            if (font == null) {
                font = UIManager.getFont("Label.font"); // $NON-NLS-1$

                if (font == null) {
                    font = g_defaultFont; // Fall back default
                }
            }

            applyProperties(comp, colBack, colFore, font);
        } // end if
    }
}

Related

  1. addMenuItem(Window window, JMenu menu, String title, String icon, int mnemonic, KeyStroke key, ActionListener listener)
  2. addMenuItems(JMenu menu, JComponent... items)
  3. addRadioButtonMenuItem(ActionListener al, JMenu m, String label, String command, boolean b, ButtonGroup g)
  4. addSeparator(JMenu menu)
  5. addSeparatorIfNeeded(JMenu menu)
  6. assignMnemonics(JMenu menu)
  7. changeMenuItemsState(final JMenu menu, final boolean enableState)
  8. constructRecentlyFilesMenuItems(JMenu recentlyOpenFilesMenuItem, LinkedHashMap filesOpenedLHM)
  9. containsMenuComponent(JMenu parent, Component comp)