import javax.swing.*; import java.awt.event.*; import javax.swing.filechooser.*; import java.awt.image.*; import java.io.File; class ImageFilter extends FileFilter { private final String[] okFileExtensions = new String[] {"jpg", "png", "gif"}; public boolean accept(File file) { if(file.isDirectory()) { return true; } for (String extension : okFileExtensions) { if (file.getName().toLowerCase().endsWith(extension)) { return true; } } return false; } public String getDescription() { return "Képfájlok"; } } class Program extends JFrame { JFileChooser fc = new JFileChooser(); JButton gomb; Program() { //~ fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter(new ImageFilter()); gomb = new JButton("Nyomj"); gomb.addActionListener(new GombClick()); add(gomb); setSize(400, 300); setVisible(true); } class GombClick implements ActionListener { public void actionPerformed(ActionEvent e) { int a = fc.showOpenDialog(Program.this); setTitle(fc.getSelectedFile().getPath()); } } public static void main(String args[]) { new Program(); } }