jfilechooser

Starting a JFileChooser at a specified directory and only showing files of a specific type

痴心易碎 提交于 2019-12-20 06:37:14
问题 I have a program utilizing a JFileChooser. To be brief, the full program is a GUI which allows users to manipulate PNGs and JPGs. I would like to make it so that the JFileChooser instantly opens to the picture directory (windows). When the user opens their JFileChooser, it would open directly to the pictures library C:\Users\(USER)\Pictures Furthermore, it would be nice to ONLY show files of a specific type (PNGs and JPGs). Many programs seem to be able to do this; only allowing selection of

java JFileChooser File Size Filter

回眸只為那壹抹淺笑 提交于 2019-12-19 12:04:18
问题 I know I can make a filter by file type, but is it possible to filter by file size? For example a JFileChooser to show only pictures within 3 MegaBytes. 回答1: The short answer should be, what have you tried? The long answer is yes... JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { String name = f.getName().toLowerCase(); return (name.endsWith(".png") && name.endsWith(".jpg") && name.endsWith(".gif") && name.endsWith("

java JFileChooser File Size Filter

丶灬走出姿态 提交于 2019-12-19 12:03:14
问题 I know I can make a filter by file type, but is it possible to filter by file size? For example a JFileChooser to show only pictures within 3 MegaBytes. 回答1: The short answer should be, what have you tried? The long answer is yes... JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { String name = f.getName().toLowerCase(); return (name.endsWith(".png") && name.endsWith(".jpg") && name.endsWith(".gif") && name.endsWith("

How to use JFileChooser to find a file location

放肆的年华 提交于 2019-12-19 10:58:53
问题 Is there a method that i can use to simply find a file location? I'm trying allow the user to choose a file and open it, but I have to have the JFileChooser just choose the file and send the location to another method. What's the best way to do this? 回答1: The example in the javadoc show show to do this: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal =

How to navigate to a network host in JFileChooser?

▼魔方 西西 提交于 2019-12-19 05:22:49
问题 The Problem I have a JFileChooser and I need to programmatically set its currentDirectory to a network host containing several SMB shares (e.g. \\blah ). Technically this is not a "directory" but rather a shell folder representing a list of available shares. JFileChooser has no problems navigating to a specific share (e.g. \\blah\someShare ) but cannot handle the host "directory" itself (e.g. \\blah ). Users can navigate to such "directories" inside JFileChooser by going via "Network" shell

Creating custom JFileChooser

↘锁芯ラ 提交于 2019-12-19 03:44:18
问题 To create an Arabic JFileChooser (RTL) I use the following: MyFileChooser: import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileView; import java.io.File; import java.awt.ComponentOrientation; import java.awt.Dimension; public class MyFileChooser extends JFileChooser { private String extension; private String title; public MyFileChooser(String extension, String

How to display default system icon for files in JFileChooser?

Deadly 提交于 2019-12-19 03:16:28
问题 How to display default system icon for files in JFileChooser ? i.e. the icons of the files in JFileChooser should be the same as the icons that appear on desktop and explorer? For example, NetBeans icon will not appear the same in JFileChooser as it appears on the desktop! How to do this? 回答1: We can use the FileSystemView class and get it's object by calling getFileSystemView() static method in it and then use the getSystemIcon() method which takes a File object and returns it's icon.

How to display default system icon for files in JFileChooser?

岁酱吖の 提交于 2019-12-19 03:16:03
问题 How to display default system icon for files in JFileChooser ? i.e. the icons of the files in JFileChooser should be the same as the icons that appear on desktop and explorer? For example, NetBeans icon will not appear the same in JFileChooser as it appears on the desktop! How to do this? 回答1: We can use the FileSystemView class and get it's object by calling getFileSystemView() static method in it and then use the getSystemIcon() method which takes a File object and returns it's icon.

How to set a default file name to Swing JFileChooser?

做~自己de王妃 提交于 2019-12-19 02:49:40
问题 I want to set a default file name as Untitled.txt in text-box of this JFileChooser . Can I set this? 回答1: Use the following code: JFileChooser fileChooser = new JFileChooser(); File file = new File("C:/untitled.txt"); fileChooser.setCurrentDirectory(file); You have to specify the complete path to untitled.txt 回答2: You have to use the setSelectedFile method and pass a file as a parameter. The file doens't have to exist. If the path to the file is specified the file chooser will try to point to

how do I make jfilechooser only accept .txt

那年仲夏 提交于 2019-12-18 11:18:45
问题 I trying to save my contact in my table but filechosser always setit to all file. is there way I can set it to accept .txt only and make it default or the only option. savecontact.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser filesave = new JFileChooser(); int returnVal = filesave.showSaveDialog(Main.this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = filesave.getSelectedFile(); PrintWriter os = new PrintWriter(file);