Adhoc selection & removal of JLabels
I have a JPanel that has thumbnails added to it. I would like to:
1. Have the thumbnail's border set to red when the thumbnail is clicked on
2. Get the index of the thumbnail as per it's position in the JPanel
3. When the "Remove" button is pressed, I'd like the selected thumbnail ( one with red border ) to be removed from the JPanel
How can I do the aforementioned?
Below is the code for adding the thumbnails to the JPanel:
Code:
class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
File[] selectedFiles;
FileBrowser browser = new FileBrowser();
// Get selected files from JFileChooser
selectedFiles = browser.browse();
filesManager.setSelectedFiles(selectedFiles);
Thumbnailer thumbnails = new Thumbnailer();
// Create thumbnails from selectedFiles
thumbnails.createThumbnails(selectedFiles);
for (Image thumbnailImage : thumbnails.getThumbnails()){
thumbnailPanel.add(new JLabel(new ImageIcon(thumbnailImage)));
}
thumbnailScroll.revalidate();
thumbnailScroll.repaint();
} // end actionPerformed method
} // end inner class ButtonHandler