We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey Guys! I had to create a custom JFileChooser for a project of mine, and since it seems to be something that is commonly needed, I thought about contributing my code to the processing github repo, but I wouldn't know where to start. Would someone want to take my code (after i give it some polishing) and contribute it?
import java.io.File; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import java.lang.management.ManagementFactory; public class Importtool { public void choose() { JFileChooser chooser = new JFileChooser(); File f = null; if(System.getProperty("os.name").equals("Linux")) { f = new File("/home"); } else if(System.getProperty("os.name").equals("Mac")) { f = new File("/home"); } else if(System.getProperty("os.name").equals("Windows")) { f = new File("Desktop"); } FileNameExtensionFilter filter = new FileNameExtensionFilter( "Images", "jpg", "gif"); FileNameExtensionFilter filter2 = new FileNameExtensionFilter( "Documents", "txt","text"); FileNameExtensionFilter filter3 = new FileNameExtensionFilter( "Video", "mp4","avi"); FileNameExtensionFilter filter4 = new FileNameExtensionFilter( "All supported filetypes", "txt","text","jpg","jpeg","tga","mp4"); chooser.setFileFilter(filter); chooser.setFileFilter(filter2); chooser.setFileFilter(filter3); chooser.setFileFilter(filter4); chooser.setDragEnabled(false); chooser.setDialogTitle("Import Manager"); chooser.setFileSelectionMode(2);//Files and directories chooser.setMultiSelectionEnabled(true); chooser.setCurrentDirectory(f); chooser.showOpenDialog(null); File[] files = chooser.getSelectedFiles(); if(files.length > 0) { for(int m = 0; m < files.length; m++) { System.out.println(files[m].getAbsolutePath()); }//or getName } else { System.out.println(files[0].getAbsolutePath()); } //chooser.getIcon(file f); //choser.getFileDescription(file f); //chooser.getCurrentDirector(file f); } }
You can email me at smeck1999@gmail.com. I know the code is rather simple, so if no one wants to add something similar to the processing library its fine. I am hoping that it will atleast be useful to some new programmer having trouble figuring this out.
Thanks! -Seth