and than I need to work with an image. If it doesn't choose right extension (jpeg, gif, etc) htan JOption window pop=ups with message "WRONG FILE". Also when it loads to JFrame it has the button "save", so it should save in in the disk.
I've got lost in loading the image via File Chooser into JFrame. Please, HELP!!!
private JFileChooser fc;
......
private JButton getJButtonOpen()
{
if (JButtonOpen == null)
{
try
{
JButtonOpen = new JButton();
JButtonOpen.setText("Open...");
JButtonOpen.setEnabled(true);
JButtonOpen.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
//Set up the file chooser.
if (fc == null) {
fc = new JFileChooser();
//Add a custom file filter and disable the default
//(Accept All) file filter.
fc.addChoosableFileFilter(new ImageFilter());
fc.setAcceptAllFileFilterUsed(false);
//Add custom icons for file types.
fc.setFileView(new ImageFileView());
//Add the preview pane.
fc.setAccessory(new ImagePreview(fc));
}
//Show it.
int returnVal = fc.showDialog(FileChooserDemo2.this,
"Attach");
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
log.append("Attaching file: " + file.getName()
+ "." + newline);
} else {
log.append("Attachment cancelled by user." + newline);
}
log.setCaretPosition(log.getDocument().getLength());
//Reset the file chooser for the next time it's shown.
fc.setSelectedFile(null);
}
});
}
catch (java.lang.Throwable e)
{
// TODO: Something
}
}
return JButtonOpen;
}

New Topic/Question
Reply



MultiQuote




|