Swing自定义水晶按钮

自定义仿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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值