Java Graphics Draw Border drawHighlightBorder(Graphics g, int x, int y, int width, int height, boolean raised, Color shadow, Color highlight)

Here you can find the source of drawHighlightBorder(Graphics g, int x, int y, int width, int height, boolean raised, Color shadow, Color highlight)

Description

Draws a single-line highlight border rectangle.

License

Open Source License

Parameter

Parameter Description
g The graphics context to use for drawing.
x The left edge of the border.
y The top edge of the border.
width The width of the border.
height The height of the border.
raised <code>true</code> if the border is to be drawn raised, <code>false</code> if lowered.
shadow The shadow color for the border.
highlight The highlight color for the border.

Declaration

public static void drawHighlightBorder(Graphics g, int x, int y, int width, int height, boolean raised,
        Color shadow, Color highlight) 

Method Source Code

//package com.java2s;
/**//  ww  w .j a  v  a 2 s .com
 * $RCSfile$
 * $Revision: 128 $
 * $Date: 2004-10-25 20:42:00 -0300 (Mon, 25 Oct 2004) $
 *
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.*;

public class Main {
    /**
     * Draws a single-line highlight border rectangle.
     *
     * @param g         The graphics context to use for drawing.
     * @param x         The left edge of the border.
     * @param y         The top edge of the border.
     * @param width     The width of the border.
     * @param height    The height of the border.
     * @param raised    <code>true</code> if the border is to be drawn raised,
     *                  <code>false</code> if lowered.
     * @param shadow    The shadow color for the border.
     * @param highlight The highlight color for the border.
     * @see javax.swing.border.EtchedBorder
     * @see javax.swing.plaf.basic.BasicGraphicsUtils#drawEtchedRect
     */
    public static void drawHighlightBorder(Graphics g, int x, int y, int width, int height, boolean raised,
            Color shadow, Color highlight) {
        final Color oldColor = g.getColor();
        g.translate(x, y);

        g.setColor(raised ? highlight : shadow);
        g.drawLine(0, 0, width - 2, 0);
        g.drawLine(0, 1, 0, height - 2);

        g.setColor(raised ? shadow : highlight);
        g.drawLine(width - 1, 0, width - 1, height - 1);
        g.drawLine(0, height - 1, width - 2, height - 1);

        g.translate(-x, -y);
        g.setColor(oldColor);
    }
}

Related

  1. drawBorder(Graphics g, Color c, int x, int y, int w, int h)
  2. drawBorder(Graphics2D g2d, Color borderColor, int x, int y, int width, int height)
  3. drawButtonBorder(Graphics g, int x, int y, int w, int h, Color backgroundColor, Color edgeColor, Color cornerColor)
  4. drawDirectionalTriangle(Graphics2D bbg, double heading, double x, double y, double sideLength, Color fillColor, Color borderColor)
  5. drawEtchedBorder(Graphics g, int x, int y, int width, int height, Color dark, Color bright)
  6. drawSquareBorder(Graphics2D g, int x, int y, int width, int height, int rounding, Color color, float strokeWidth)
  7. paintBorder(Graphics g, int borderType, Insets insets, Color[] colors, int width, int height)
  8. paintBorder(Rectangle r, Graphics2D g2d)
  9. paintBorderDebugInfo(final Graphics g, final JComponent c, final Color color)