the problem is with your code order you added the buttons to contentpane before initializing them, change them as below:

jbArray = new JButton [countryArray.length];

for (int i = 0; i<jbArray.length; i++)
{
    jbArray[i] = new JButton(alist.get(i).getName());
    ImageIcon ic = new ImageIcon (alist.get(i).getName() +".png");
    
    jbArray[i].setIcon(ic);

}

for (int i = 0; i< jbArray.length; i++)
{
    getContentPane().add(jbArray[i]);
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top