private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//Read the image file into an ImageIcon object
JFileChooser fileChooser = new JFileChooser();
int status = fileChooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION)
{
File selectedFile = fileChooser.getSelectedFile();
String filename = selectedFile.getPath();
imageLabel.setIcon(filename);
}
//Pack the frame again to accomodate the new size of the label
pack();
}
}
Displaying an image via filechooser
Page 1 of 13 Replies - 966 Views - Last Post: 22 October 2011 - 02:48 PM
#1
Displaying an image via filechooser
Posted 22 October 2011 - 02:26 PM
I'm not sure how to display the image that gets selected after it has been chosen from the fileChooser.
Replies To: Displaying an image via filechooser
#3
Re: Displaying an image via filechooser
Posted 22 October 2011 - 02:46 PM
Got it. Thanks again!
Conclusive code
Conclusive code
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//Read the image file into an ImageIcon object
JFileChooser fileChooser = new JFileChooser();
int status = fileChooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION)
{
File selectedFile = fileChooser.getSelectedFile();
String filename = selectedFile.getPath();
ImageIcon image = new ImageIcon(filename);
imageLabel.setIcon(image);
}
#4
Re: Displaying an image via filechooser
Posted 22 October 2011 - 02:48 PM
Glad I could help!
Page 1 of 1

New Topic/Question
Reply


MultiQuote





|