I have my JLabel change as a JComboBox selection changes. I had originally used:
ImageIcon icon2 = new ImageIcon(ClassLoader.getSystemResource("images/image.png"));
and an action event which worked fine with the compiler. When I tried to export it as a .jar the files wouldn't load or switch. So I did some research and switched to using this method to get my pictures:
ImageIcon icon2 = new ImageIcon(getClass().getClassLoader().getResource("/images/image.png"));
Now when I try to switch the JComboBox selection the image does not change or appear. I have my images in an array as seen below.
final String[] images = {"birch_river.png", "elm_american.png", "maple_bigtooth.png", "oak_bur.png", "white_pine.png", "oak_willow.png"};
And here is the action:
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
JComboBox treeSelectBox = (JComboBox) e.getSource();
int index = treeSelectBox.getSelectedIndex();
//display.setIcon(new ImageIcon(ClassLoader.getSystemResource(images[index])));
display.setIcon(new ImageIcon(tabbedTreeSafe.class.getResource(images[index])));
descript.setText(treeDescription[index]);
}
}
display is the JLabel where the images appear, and descript is just an array with a description of the image.