Swinghacks——用圖片自訂按鈕

來源:互聯網
上載者:User

記得大學時候寫網站,會要求美工設計超連結時,需要設計 正常顯示的樣式、滑鼠滑過的樣式、滑鼠按住的樣式 等等

今天看swinghacks發現原來swing中的按鈕已經有這種封裝的方法,就在AbstractButton類中,調用也很簡單,如下:

        JButton button = new JButton("images/button.png");        button.setPressedIcon(new ImageIcon("images/button-down.png"));        button.setRolloverIcon(new ImageIcon("images/button-over.png"));        button.setSelectedIcon(new ImageIcon("images/button-sel.png"));        button.setRolloverSelectedIcon(new ImageIcon("images/button-sel-over.png"));        button.setDisabledIcon(new ImageIcon("images/button-disabled.png"));        button.setDisabledSelectedIcon(new ImageIcon("images/button-disabled-selected.png"));

個人覺得,這些方法應該很少用到吧。swing的難看已經不是一天兩天了,通過image來彌補也不是高效的解決方案,貌似只能將就了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.