Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Xapp (pronounced Zap!), A automatic gui tool for Java.
 * Copyright (C) 2009 David Webber. All Rights Reserved.
 *
 * The contents of this file may be used under the terms of the GNU Lesser
 * General Public License Version 2.1 or later.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 */

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;

public class Main {
    public static Font DEFAULT_FONT = Font.decode("dialog-10");

    public static void setFont(Container container) {
        setFont(container, DEFAULT_FONT);
    }

    public static void setFont(Container container, String fontStr) {
        setFont(container, Font.decode(fontStr));
    }

    public static void setFont(Container container, Font font) {
        container.setFont(font);
        trySetBorderFont(font, container);
        Component[] components = container.getComponents();
        for (Component component : components) {
            component.setFont(font);
            if (component instanceof Container) {
                setFont((Container) component, font);
            }
            trySetBorderFont(font, component);
            if (component instanceof JTable) {
                JTable table = (JTable) component;
                table.getTableHeader().setFont(font);
            }
        }

        if (container instanceof JMenu) {
            JMenu jMenu = (JMenu) container;
            for (int i = 0; i < jMenu.getItemCount(); i++) {
                JMenuItem mi = jMenu.getItem(i);
                mi.setFont(font);
            }
        }
    }

    private static void trySetBorderFont(Font font, Component component) {
        if (component instanceof JComponent) {
            JComponent jc = (JComponent) component;
            if (jc.getBorder() instanceof TitledBorder) {
                TitledBorder titledBorder = (TitledBorder) jc.getBorder();
                titledBorder.setTitleFont(font);
            }
        }
    }
}