Java JButton Settings drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active)

Here you can find the source of drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active)

Description

draw Default Button Border

License

Open Source License

Declaration

static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics;

import java.awt.Rectangle;

import javax.swing.plaf.metal.MetalLookAndFeel;

public class Main {
    static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
        drawButtonBorder(g, x + 1, y + 1, w - 1, h - 1, active);
        g.translate(x, y);//from w  w w  .j a  va  2 s  .com
        g.setColor(MetalLookAndFeel.getControlDarkShadow());
        g.drawRect(0, 0, w - 3, h - 3);
        g.drawLine(w - 2, 0, w - 2, 0);
        g.drawLine(0, h - 2, 0, h - 2);
        g.translate(-x, -y);
    }

    static void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
        if (active) {
            drawActiveButtonBorder(g, x, y, w, h);
        } else {
            drawFlush3DBorder(g, x, y, w, h);
        }
    }

    static void drawActiveButtonBorder(Graphics g, int x, int y, int w, int h) {
        drawFlush3DBorder(g, x, y, w, h);
        g.setColor(MetalLookAndFeel.getPrimaryControl());
        g.drawLine(x + 1, y + 1, x + 1, h - 3);
        g.drawLine(x + 1, y + 1, w - 3, x + 1);
        g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
        g.drawLine(x + 2, h - 2, w - 2, h - 2);
        g.drawLine(w - 2, y + 2, w - 2, h - 2);
    }

    static void drawFlush3DBorder(Graphics g, Rectangle r) {
        drawFlush3DBorder(g, r.x, r.y, r.width, r.height);
    }

    /**
      * This draws the "Flush 3D Border" which is used throughout the Metal L&F
      */
    static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {
        g.translate(x, y);
        g.setColor(MetalLookAndFeel.getControlDarkShadow());
        g.drawRect(0, 0, w - 2, h - 2);
        g.setColor(MetalLookAndFeel.getControlHighlight());
        g.drawRect(1, 1, w - 2, h - 2);
        g.setColor(MetalLookAndFeel.getControl());
        g.drawLine(0, h - 1, 1, h - 2);
        g.drawLine(w - 1, 0, w - 2, 1);
        g.translate(-x, -y);
    }
}

Related

  1. doClick(final AbstractButton button)
  2. doHover(boolean b, AbstractButton... btns)
  3. doSetText(final AbstractButton abstractButton, final String text)
  4. doSetTextInEDT(final AbstractButton abstractButton, final String text)
  5. drawActiveButtonBorder(Graphics g, int x, int y, int w, int h)
  6. emphasizeButton(AbstractButton btn)
  7. equalizeButtonSizes(JPanel jPanelButtons)
  8. filterMnemonic(final String s, final AbstractButton b)
  9. findButton(Container container, String text)