Draws a 3d hightlight frame around the designated rectangle. - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

Draws a 3d hightlight frame around the designated rectangle.

Demo Code

/*//from  w  ww .  ja  va 2s . c o m
 * @(#) GUIUtils
 *
 * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement.  
 * Contributors retain copyright to elements licensed under a Contributor Agreement.
 * Licensed to the User under the LGPL license.
 *
 */
//package com.java2s;
import java.awt.*;

public class Main {
    /**
     * Draws a 3d hilite frame around the designated rectangle.
     *
     * @param g The graphics context that will be drawn upon.
     * @param rect The rectangle that marks the bounds of the 3d frame
     * @param colorBackground The background color that will be painted within
     *        the frame.
     */
    public static void draw3dHiliteFrame(Graphics g, Rectangle rect,
            Color colorDark, Color colorLight) {
        Color colorOld = g.getColor();

        // Draw borders
        g.setColor(colorDark);

        /*
         * First draw a dark rectangle
         */
        g.drawRect(rect.x, rect.y, rect.width - 2, rect.height - 2);

        /*
         * Fill in lite areas
         */
        g.setColor(colorLight);

        //    __
        //   x__|
        //
        g.drawLine(rect.x + 1, rect.y + 1, rect.x + 1, rect.y
                + (rect.height - 3));

        //    xx
        //   |__|
        //
        g.drawLine(rect.x + 1, rect.y + 1, rect.x + (rect.width - 3),
                rect.y + 1);

        //    __
        //   |  |
        //    xx
        g.drawLine(rect.x + 1, rect.y + (rect.height - 1), rect.x
                + (rect.width - 1), rect.y + (rect.height - 1));

        //    __
        //   |__x
        //
        g.drawLine(rect.x + (rect.width - 1), rect.y, rect.x
                + (rect.width - 1), rect.y + (rect.height - 1));

        g.setColor(colorOld);
    }
}

Related Tutorials