I am trying to set the icon for a JLabel in a synth xml file but it does not display. I have tried to set both the defaultIcon and icon properties and none seem to be taking. Should I be using something other than a JLabel here? Here's my code:
<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;
}
I know this is late, but maybe it helps someone else.
I managed to add an image by using
<imagePainter path="images/WG_selectionFields-2.png"" sourceInsets="1 1 5 5" />
instead of using imageIcon. I hope this helps!