JFileChooser chooser = new JFileChooser(System.getProperty(" user.home"));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
chooser.setDialogTitle("Inserting Picture");
chooser.setAccessory(new Viewe(chooser));
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
} else {
return file.getName().toLowerCase().endsWith(".jpeg")
|| file.getName().toLowerCase().endsWith(".jpg")
|| file.getName().toLowerCase().endsWith(".gif")
|| file.getName().toLowerCase().endsWith(".tiff")
|| file.getName().toLowerCase().endsWith(".tif")
|| file.getName().toLowerCase().endsWith(".png")
|| file.getName().toLowerCase().endsWith(".txt");
}
}
@Override
public String getDescription() {
return "Portable Network Graphics (*.png)";
}
});
int res = chooser.showOpenDialog(Show_Average.this);
if (res == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
//create ImageIcon out of the selected file
ImageIcon image = new ImageIcon(file.getAbsolutePath());
// get width and hight of picLabel
Rectangle rect = label.getBounds();
// scaling the Image to fit in the lable
Image scaledImage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_SMOOTH);
image = new ImageIcon(scaledImage);
label.setIcon(image);
} else {
}