Search code examples
javaimageiconjtogglebutton

Creating multiple JToggleButton with indivdual ImageIcon


    ImageIcon img_1 = new ImageIcon("src/menu/btn_1.jpg");
    ImageIcon img_2 = new ImageIcon("src/menu/btn_2.jpg");
    ImageIcon img_3 = new ImageIcon("src/menu/btn_3.jpg");
    ImageIcon img_4 = new ImageIcon("src/menu/btn_4.jpg");
    ImageIcon img_5 = new ImageIcon("src/menu/btn_5.jpg");
    ImageIcon img_6 = new ImageIcon("src/menu/btn_6.jpg");
    ImageIcon img_7 = new ImageIcon("src/menu/btn_7.jpg");
    ImageIcon img_8 = new ImageIcon("src/menu/btn_8.jpg");
    ImageIcon img_9 = new ImageIcon("src/menu/btn_9.jpg");

    bgNumbers = new ButtonGroup();
    btnNumbers = new JToggleButton[9];
    for (int i = 0; i < 9; i++) {
        btnNumbers[i] = new JToggleButton(???);
         .....
         .....
    }

How do I insert the individuals ImageIcon img_1, img_2 ....... img_9 into the loop?


Solution

  • Add them to an array instead of individual variables. – Gábor Bakos Apr 4 at 7:35