2011-10-26 41 views
1

我正在嘗試在合成器xml文件中設置JLabel的圖標,但它不顯示。我曾嘗試設置defaultIcon和圖標屬性,但似乎沒有任何提示。我應該在這裏使用除JLabel之外的其他東西嗎?這裏是我的代碼:在Synth xml中設置JLabel圖標

<style id="dayBgLabelStyle"> 
    <imageIcon id="bg" path="images/WG_selectionFields-2.png"/> 
    <property key="defaultIcon" value="bg"/> 
    <property key="icon" value="bg"/> 
</style> 

<bind style="dayBgLabelStyle" type="name" key="dayBgLabel"/> 

JLabel dayBgLabel = new JLabel(); 
dayBgLabel.setName("dayBgLabel"); 
dayBgLabel.setIcon(createImageIcon("images/selectionFields-2.png")); 

protected static ImageIcon createImageIcon(String path) { 
    java.net.URL imgURL = testClass.class.getResource(path); 
    if (imgURL != null) 
     return new ImageIcon(imgURL); 
    else 
     return null; 
} 
+0

您能否爲您創建的合成器樣式添加裝訂線? – Joshua

回答

0

我知道這是晚了,但也許它可以幫助別人。

我設法用

<imagePainter path="images/WG_selectionFields-2.png"" sourceInsets="1 1 5 5" />

,而不是使用的ImageIcon添加圖像。我希望這有幫助!