I am trying to load some images in a scrollable pane. But for some reason it is not showing up. Here is my piece of code to add Images.
private JFileChooser fileChooser = new JFileChooser(){
@Override
public void approveSelection(){
File files[] = fileChooser.getSelectedFiles();
JPanel panel = new JPanel(new GridLayout(files.length, 1));
for(int lop=0; lop< files.length; lop++){
BufferedImage image = null;
try {
image = ImageIO.read(files[lop]);
} catch (IOException ex) {}
BufferedImage img = new BufferedImage(100, 100, 1);
Graphics2D g = img.createGraphics();
g.drawImage(image, 0, 0, 100, 100, null);
g.dispose();
ImageIcon icon = new ImageIcon(img);
JLabel lable = new JLabel(icon);
panel.add(lable);
}
jScrollPane1.getViewport().add(panel);
super.approveSelection();
}
};
Using above fileCHooser, I select some images to load in a vertical scrollPane, somehow, scrollPane horizontal scroller shows up change in length, but there are no contents in the scrollpane. Please check following screenshot. under the title of Shapes: you will see an empty container with extended scrollbars

regards,
Aqif Hamid
The problem is with this line of code:
Why do you create a JFrame?
You should just create the JScrollPane like this:
Or set the view of the scrollpane like this:
Also, you should just use
panel.add(lable). The GridLayout will put the label at the appropriate location.And you should not ignore exceptions. Transform the empty catch block to: