2013-12-13 121 views
7

我將我的按鈕圖標設置爲我在photoshop中製作的.png,而不是隻顯示圖像,然後仍然有按鈕邊框或任何您想調用它的圖標。Java JButton only image?

enter image description here

我希望按鈕只是:

enter image description here

+1

您使用什麼樣的外觀和感覺?你可以刪除邊框,將'Insets'放入0 – nachokk

+0

這個以前的問題可能會幫助你[鏈接](http://stackoverflow.com/questions/18468169/is-there-any-way-to-fit-an-image- in-a-tab-component) – nachokk

回答

13

there are set of methods implemented in API創建未修飾JButton,例如

JButton button = new JButton(); 
button.setBorderPainted(false); 
button.setBorder(null); 
//button.setFocusable(false); 
button.setMargin(new Insets(0, 0, 0, 0)); 
button.setContentAreaFilled(false); 
button.setIcon(myIcon1); 
button.setRolloverIcon(myIcon2); 
button.setPressedIcon(myIcon3); 
button.setDisabledIcon(myIcon4); 
+0

非常感謝您 – Paludan

+0

不用客氣 – mKorbel

2

你剛剛錯過了一條線。

btn.setBorder(null);是您唯一需要做的事情。休息是完美的。

0

添加它使其完美:button.setFocusPainted(false);

+0

您可以擴展一下您的答案嗎? – Rakete1111