[code]package com.promosoft.Util;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JApplet;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
public class TestarFileChooser extends JApplet {
private Component me;
//Methods to load on applet initialisation
public void init() {
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
guiLayout();
}
});
} catch (Exception e) {
System.err.println("guiLayout didn't successfully complete");
}
me = this;
}
public void start() {
}
public void stop() {
}
// **********************************************************
// * *
// * This method dictates the GUI Layout of the Applet *
// * *
// **********************************************************
public void guiLayout() {
//Where the GUI is created:
JPanel files_local;
// The left panel for local file handler
files_local = new JPanel();
getContentPane().add(files_local, BorderLayout.LINE_START);
final JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new ImageFilter());
fc.setAcceptAllFileFilterUsed(false);
fc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.out.println("Cancelar :" + e.getActionCommand());
String returnAction = e.getActionCommand();
if (returnAction.equals(JFileChooser.APPROVE_SELECTION))
{
File file = fc.getSelectedFile();
if (file!=null)
{
System.out.println("Valor do File: "+file.getAbsolutePath());
}
}
}
});
//Add custom icons for file types.
fc.setFileView(new ImageFileView());
//Add the preview pane.
fc.setAccessory(new ImagePreview(fc));
//Reset the file chooser for the next time it's shown.
fc.setSelectedFile(null);
files_local.add("Center", fc);
fc.validate();
}
}[/code]
[size=“11”][color=“red”]* Editado: Lembre-se de utilizar BBCode em seus códigos - Ratinho[/color][/size] :joia: