Java examples for Swing:Border
Draws an active button border (normal state).
/*/*ww w . jav a 2s.c o m*/ * blue - object composition environment for csound * Copyright (c) 2000-2004 Steven Yi (stevenyi@gmail.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License or * (at your option) any later version. * * 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; see the file COPYING.LIB. If not, write to * the Free Software Foundation Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307 USA * * This file uses code from MetouiaBorderUtilities.java by Taoufik Romdhane * */ import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.basic.BasicBorders; public class Main{ /** * Draws an active button border (normal state). * * @param g * The graphics context. * @param x * The x coordinate of the top left corner. * @param y * The y coordinate of the top left corner. * @param w * The width. * @param h * The height. */ static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h) { drawSimple3DBorder(g, x + 1, y + 1, w - 2, h - 2, BlueLookAndFeel.getControlDarkShadow(), BlueLookAndFeel.getControlHighlight()); g.setColor(new Color(255, 255, 255, 128)); g.drawLine(x + 2, y + 2, x + w - 3, y + 2); //g.drawRect(x, y, w - 1, h - 1); } /** * Draws a simple 3d border. * * @param g * The graphics context. * @param r * The rectangle object defining the bounds of the border. */ static void drawSimple3DBorder(Graphics g, Rectangle r) { drawSimple3DBorder(g, r.x, r.y, r.width, r.height); } /** * Draws a simple 3d border. * * @param g * The graphics context. * @param x * The x coordinate of the top left corner. * @param y * The y coordinate of the top left corner. * @param w * The width. * @param h * The height. */ static void drawSimple3DBorder(Graphics g, int x, int y, int w, int h) { drawSimple3DBorder(g, x, y, w, h, BlueLookAndFeel.getControlDarkShadow(), BlueLookAndFeel.getControlHighlight()); } /** * Draws a simple 3d border with specified colors. * * @param g * The graphics context. * @param x * The x coordinate of the top left corner. * @param y * The y coordinate of the top left corner. * @param w * The width. * @param h * The height. * @param highlight * The highlight color to use. * @param shadow * The shadow color to use. */ public static final void drawSimple3DBorder(Graphics g, int x, int y, int w, int h, Color highlight, Color shadow) { g.translate(x, y); g.setColor(highlight); g.drawLine(0, 0, w - 2, 0); g.drawLine(0, 1, 0, h - 1); g.setColor(shadow); g.drawLine(w - 1, 0, w - 1, h - 2); g.drawLine(1, h - 1, w - 1, h - 1); g.translate(-x, -y); } }