Hi,
I am trying to add buttons to a Panel which is located on JFrame after the JFrame has been set to visible.
My aim is to be able to click "File --> Load" then have it loop through a folder of images,
creating buttons which have the images on them, and then adding them to the JPanel.
Below is the actionevent section which is supposed to load the images and store the buttons in a list. NOTE: TileButton is a class which inherrits JButton - and i have added a few of my own methods.
if(ae.getActionCommand() == "Load Images") {
File folder = new File("./images");
File[] files = folder.listFiles();
System.out.println("Here");
TileButton button;
for(int i = 0; i < files.length; i++) {
System.out.println(files[i].getPath());
button = new TileButton();
button.addActionListener(this);
button.setIsSet(true);
button.setIcon(files[i].getAbsolutePath());
buttonList.add(i, button);
//System.out.println(button.getIcon().getIconHeight() + ":" + button.isSet());
objPanel.add(buttonList.get(i));
}
/* Test Button Part */
}
The printouts on the code above all work properly, but the buttons never show up on the panel.
I have tried repainting the panel and Jframe.
I have had buttons display on the panel before I set the Jframe to visible, just not after.
I have only posted a small but of code - if anyone needs more I shall post it.
Thanks.