|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.welcome.ui; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class OvalButton extends JButton { Color bgColor , fgColor, focusColor, depColor, lineColor, rollColor; private boolean mouseInside = false; public OvalButton(int bgColor, int fgColor, int lineColor, int focusColor, int depColor, int rollColor) { super(); this.bgColor = new Color(bgColor); this.fgColor = new Color(fgColor); this.lineColor = new Color(lineColor); this.focusColor = new Color(focusColor); this.depColor = new Color(depColor); this.rollColor = new Color(rollColor); this.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { mouseInside = true; repaint(0); } public void mouseExited(MouseEvent e) { mouseInside = false; repaint(0); } }); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; int xx = getWidth(); int yy = getHeight(); // don't draw background // g2d.setColor(bgColor); // g2d.fillRect(0,0,xx,yy); int lw = this.hasFocus() ? 2 : 1; g2d.setColor(getModel().isArmed() ? depColor : (this.hasFocus()?focusColor: (mouseInside? rollColor : fgColor) )); g.fillRoundRect(lw,lw,xx-2*lw,yy-2*lw,6,6); g2d.setColor(hasFocus()?Color.WHITE : lineColor); g2d.setStroke(new BasicStroke(lw)); g.drawRoundRect(lw,lw,xx-2*lw,yy-2*lw,6,6); Font f = new Font("SansSerif", Font.BOLD, 12); FontMetrics fm = g.getFontMetrics(f); g.setFont(f); g.drawString(getText(),15, yy/2 + (fm.getAscent()+fm.getDescent())/2 - fm.getDescent()); } public boolean isOpaque() { return false;} } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.