Java Swing UIManager paintFocus(Graphics2D g, Shape shape, int biggestStroke)

Here you can find the source of paintFocus(Graphics2D g, Shape shape, int biggestStroke)

Description

Paints 3 different strokes around a shape to indicate focus.

License

Open Source License

Parameter

Parameter Description
g the graphics to paint to
shape the shape to outline
biggestStroke the widest stroke to use.

Declaration

public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) 

Method Source Code


//package com.java2s;
/*/*from  w w w  .ja  va2 s  . c o m*/
* @(#)PaintUtils.java  1.0  2008-03-01
*
* Copyright (c) 2008 Jeremy Wood
* E-mail: mickleness@gmail.com
* All rights reserved.
*
* The copyright of this software is owned by Jeremy Wood.
* You may not use, copy or modify this software, except in
* accordance with the license agreement you entered into with
* Jeremy Wood. For details see accompanying license terms.
*/

import java.awt.*;
import javax.swing.*;

public class Main {
    /** Paints 3 different strokes around a shape to indicate focus.
     * The widest stroke is the most transparent, so this achieves a nice
     * "glow" effect.
     * <P>The catch is that you have to render this underneath the shape,
     * and the shape should be filled completely.
     *
     * @param g the graphics to paint to
     * @param shape the shape to outline
     * @param biggestStroke the widest stroke to use.
     */
    public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) {
        Color focusColor = getFocusRingColor();
        Color[] focusArray = new Color[] {
                new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 255),
                new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 170),
                new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 110) };
        g.setStroke(new BasicStroke(biggestStroke));
        g.setColor(focusArray[2]);
        g.draw(shape);
        g.setStroke(new BasicStroke(biggestStroke - 1));
        g.setColor(focusArray[1]);
        g.draw(shape);
        g.setStroke(new BasicStroke(biggestStroke - 2));
        g.setColor(focusArray[0]);
        g.draw(shape);
        g.setStroke(new BasicStroke(1));
    }

    /** @return the color used to indicate when a component has
     * focus.  By default this uses the color (64,113,167), but you can
     * override this by calling:
     * <BR><code>UIManager.put("focusRing",customColor);</code>
     */
    public static Color getFocusRingColor() {
        Object obj = UIManager.getColor("focusRing");
        if (obj instanceof Color)
            return (Color) obj;
        return new Color(64, 113, 167);
    }
}

Related

  1. makeNative()
  2. makeSplitpaneNice()
  3. makeToolbarNice()
  4. noAltBg()
  5. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  6. paintFocus(Graphics2D g, Shape shape, int biggestStroke)
  7. paintUnderlying(Graphics g, JComponent c)
  8. paintXpTabHeader(int type, Graphics g, int x, int y, int width)
  9. prepareGUI(final String appName)