ImageIcon array. How to grab images from source folder and set JToggleButton icon?

33 Views Asked by At
    public class DisplayPanel extends JPanel {

        private final static ButtonGroup buttonGroup = new ButtonGroup();


        static JRadioButton [] radioButtons = new JRadioButton [4];
        static JLabel [] labels = new JLabel [4];

        ImageIcon [] icons = {

                new ImageIcon("HEX Disabled.jpg"), 
                new ImageIcon("DEC Disabled.jpg"),
                new ImageIcon("OCT Disabled.jpg"),
                new ImageIcon("BIN Disabled.jpg")
        };

        ImageIcon [] selectedIcons = {

                new ImageIcon("HEX Selected.jpg"),
                new ImageIcon("DEC Selected.jpg"),
                new ImageIcon("OCT Selected.jpg"),
                new ImageIcon("BIN Selected.jpg")
        };

  more stuff here.... 

And then I try to set the icon here inside a for loop...

radioButtons[i].setSelectedIcon(icons[i]);
radioButtons[i].setSelectedIcon(selectedIcons[i]);

My question is, if I have a source folder called "icons", how exactly can I access that folder and use the images within to set the icons for my buttons?

I've tried....

new ImageIcon("img/HEX Selected.jpg"),

I've also tried putting in the the bin folder and using

new ImageIcon("bin/HEX Selected.jpg"),

as well as

new ImageIcon("bin\\HEX Selected.jpg"),

What do I need to correct here to make it work?

Thanks,

Thomas

0

There are 0 best solutions below