ÖffnenDialog
Aus Programmers Guide
Version vom 10:19, 30. Mär. 2010 bei Roy (Diskussion | Beiträge)
OeffnenDialog
import java.awt.Color; import java.io.File; import javax.swing.JFileChooser; /** * @author Roy Klasse zum Öffnen eines DialogFensters */ public class OeffnenDialog { private static String inputVerzStr = null; private final JFileChooser chooser; public OeffnenDialog(){ chooser = new JFileChooser(); chooser.addChoosableFileFilter(new OeffnenDialogFilter()); chooser.setCurrentDirectory(new java.io.File("C:/")); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); } public String retour() { chooser.setVisible(true); final int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File inputVerzFile = chooser.getSelectedFile(); inputVerzStr = inputVerzFile.getPath(); } chooser.setVisible(false); return inputVerzStr; } }
OeffnenDialogFilter
import java.io.File; /** * @author Roy Diese Klasse filtert die vom FileChooser genutzten Dateien */ class OeffnenDialogFilter extends javax.swing.filechooser.FileFilter { @Override public boolean accept(File file) { String filename = file.getName(); return (file.isDirectory() || filename.endsWith(".mdb")); } @Override public String getDescription() { return "*.mdb"; } }