自定义仿Win7的水晶按钮
效果图
完整工程下载http://download.csdn.net/detail/jasper_success/4488514
关键代码
- public void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- AlphaComposite composite = AlphaComposite.getInstance(
- AlphaComposite.SRC_OVER, alpha);
- g2.setComposite(composite);
-
-
- if (this.isMouseEntered) {
- Util.drawButtonBackground(g2, this, new Color(253, 236, 219),
- new Color(253, 223, 187), new Color(255, 206, 105),
- new Color(255, 255, 222));
- }
-
- if (clicked) {
- Util.drawButtonBackground(g2, this, new Color(255, 199, 99),
- new Color(253, 236, 219), new Color(253, 236, 219),
- new Color(255, 199, 99));
- }
- composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
- g2.setComposite(composite);
- if (frameType == FRAME_AROUND) {
- g.setColor(Config.COLOR_TOOLBAR_FRAME);
- g.drawRoundRect(1, 1, getWidth() - 4, getHeight() - 2, 3, 3);
- } else if (frameType == FRAME_RIGHT) {
- g.setColor(Config.COLOR_TOOLBAR_FRAME);
- g.drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 2);
- }
-
-
- Util.setFractionalmetricsOn(g2);
-
- g.setColor(Config.COLOR_UI_TEXT);
- g.setFont(Config.FONT_UI_TEXT);
-
-
- if (getImage() != null) {
- g.drawImage(getImage(),
- (getWidth() - getImage().getWidth(this)) / 2, 5 + mbStatus,
- this);
- g.drawString(getName(), (getWidth() - getName().length()
- * Config.FONT_UI_TEXT.getSize()) / 2,
- getImage().getHeight(this) + mbStatus);
- } else {
- g.drawString(getName(), (getWidth() - getName().length()
- * Config.FONT_UI_TEXT.getSize()) / 2, 10 + mbStatus);
- }
- }
下载http://download.csdn.net/detail/jasper_success/4488514
|