Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Rectangle;

import javax.swing.AbstractButton;

import javax.swing.Icon;

import javax.swing.JComponent;

import javax.swing.SwingUtilities;

public class Main {
    public static String layoutCustomButton(AbstractButton b, Icon icon, Rectangle viewRect, Rectangle iconRect,
            Rectangle textRect) {
        return layoutComponent(b, b.getText(), icon, b.getIconTextGap(), b.getVerticalAlignment(),
                b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect,
                iconRect, textRect);
    }

    public static String layoutComponent(JComponent c, String text, Icon icon, int iconTextGap,
            int verticalAlignment, int horizontalAlignment, int verticalTextAlignment, int horizontalTextAlignment,
            Rectangle viewRect, Rectangle iconRect, Rectangle textRect) {
        resetRectangles(iconRect, textRect);

        return SwingUtilities.layoutCompoundLabel(c, c.getFontMetrics(c.getFont()), text, icon, verticalAlignment,
                horizontalAlignment, verticalTextAlignment, horizontalTextAlignment, viewRect, iconRect, textRect,
                iconTextGap);
    }

    /**
     * Resets the specified {@code Rectangle}'s properties to 0.
     * 
     * @param rects the rectangles to reset
     */
    public static void resetRectangles(Rectangle... rects) {
        for (Rectangle r : rects) {
            r.x = r.y = r.width = r.height = 0;
        }
    }
}