Swing自訂水晶按鈕

來源:互聯網
上載者:User

自訂仿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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.