jfilechooser

JFileChooser - multiple file filters?

烂漫一生 提交于 2019-12-04 03:57:26
I have a question about the JFileChooser in Swing. I'm trying to get multiple file extensions in the drop-down box, but have no idea how to do it. There is the method extFilter = FileNameExtensionFilter(description, extensions); that I can then use by writing fileChooser.setFileFilter(extFilter); however, as you can see, this only supports one option in the drop-down list. How do I add more? I think you want the addChoosableFileFilter method. Read the tutorial . You can simply create a filter that subclasses FileFilter and call the method I outlined above with that filter as an argument. I'm

altering JFileChooser behaviour : preventing “choose” on enter in file path JTextField

跟風遠走 提交于 2019-12-04 03:40:51
问题 Greetings to Swing Pros, here's a good (I hope) question for you. The below are the task requirements and possible solutions I see. I would like someone having had such a hardcore experience to share some thoughts about this. This does not require coding or anything like that, I just need general advice as to which approach is more reliable regarding the fact I need to work with private symbols which reside in sun.swing and/or javax.swing.plaf packages. The task is to modify/alter

JFileChooser and browsing networked machines [closed]

落花浮王杯 提交于 2019-12-04 01:38:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am working on a little program that needs the ability to let users browse files and directories on networked machines as well as the local filesystem. I made the mistake of developing this component on a Windows machine... it worked fine there, but hid the fact that JFileChooser doesn't really "see" networked

How to restrict file choosers in java to specific files

不羁的心 提交于 2019-12-04 01:02:48
private void openMenuActionPerformed(java.awt.event.ActionEvent evt) { DBmanager db = new DBmanager(); if (!db.getCurrentUser().equals("Admin")) { JOptionPane.showMessageDialog(this, "You are Not Allowed to Run Applications"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Documents", "pdf")); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("MS Office Documents", "docx", "xlsx", "pptx")); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter(

jfilechooser - set directory to a path in a file

我与影子孤独终老i 提交于 2019-12-03 23:31:02
I am trying to set the directory path in JFilechooser through something like this(using commons-io ) : String fileContents = IOUtils.toString(new FileInputStream("path.txt")); File theDirectory = new File(fileContents); filechooser = new JFileChooser(); fileChooser.setCurrentDirectory(theDirectory); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); I'm using getCanonicalPath() to get the path and write in the file path.txt path = file.getCanonicalPath(); I don't intend to put all my code here,but I'm sure that the program writes and reads the path in path.txt. I don't get any

Get the path of a directory using JFileChooser

岁酱吖の 提交于 2019-12-03 18:05:54
问题 How can I get the absolute path of a directory using JFileChooser, just selecting the directory? 回答1: Use: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //or chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); together with: chooser.getCurrentDirectory() //or chooser.getSelectedFile(); then call getAbsoluteFile() on the File object returned. 回答2: JFileChooser 's getSelectedFile() method, returns a File object. Use the getAbsolutePath() to get the absolute name to

Change the location of the accessory component in a filechooser

こ雲淡風輕ζ 提交于 2019-12-03 18:05:37
问题 I have a problem in changing the location of the accessory component in a filechooser. I customized a save file dialog by putting a check box in the accessory component of the file chooser. But the position of the check box is not good, it is really ugly. Can I move the accessory component to be underneath the file pane? How to do it? Or if you have other solution to do the same thing, also welcome. Thank you guys. I using following code to add the check box: JFileChooser fc = new

how to import datas from excel to jTable?

安稳与你 提交于 2019-12-03 17:52:00
JFileChooser fc = new JFileChooser(); int option = fc.showSaveDialog(NewJFrame1.this); if(option == JFileChooser.APPROVE_OPTION){ String filename = fc.getSelectedFile().getName(); String path = fc.getSelectedFile().getParentFile().getPath(); int len = filename.length(); String ext = ""; String file = ""; if(len > 4){ ext = filename.substring(len-4, len); } if(ext.equals(".xls")){ file = path + "\\" + filename; }else{ file = path + "\\" + filename + ".xls"; } toExcel(jTable1, new File(file)); } this is how i save my table to excel it works fine but i want to import these datas after i restart

Set locale properly to a JFileChooser

与世无争的帅哥 提交于 2019-12-03 16:25:54
I'm having a little problem when I change Locale at runtime. The Goal I have to change the Locale of my application language according to a configuration file. This locale does not necessarily be the same of the host/OS locale nor the JVM default locale. Moreover, I can't modify user.language when I call the application. Then, I must do that at runtime. The Problem Summarizing my code, I read the configuration file and get the different options (including locale). After that, I initialize the application environment according to these configured options. After, I build my frame and starts the

Open only .xml file in JFileChooser

家住魔仙堡 提交于 2019-12-03 15:29:31
I am developing a java application for which I need only .xml files. Now I want to show only .xml files in JFileChooser whenever user wants to save a file or open a existing file. Is this possible to show only .xml files? Java You can use JFileChooser API to achieve your task. For Open only .xml file // create a filechooser; JFileChooser chooser = new JFileChooser(cwd); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter( "xml files (*.xml)", "xml"); chooser.setDialogTitle("Open schedule file"); // set selected filter chooser.setFileFilter(xmlfilter); Also, go through javax.swing