jfilechooser

Repurposing JFileChooser

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:39:47
问题 I need to implement file browsing feature in my app and while I am aware of possibility of making a JList item and doing it manually I had an idea to just implement JFileChooser for this. I managed to reduce the JFileChooser just to list of directories and files but I wasn't able to override some of it's functionalities. I have been going through source code but no luck. My idea is for it to handle as following: On the top of the list to have a /... directory so when clicked on it it returns

How can I make JFileChooser behave properly with disconnected network drives?

流过昼夜 提交于 2019-12-11 09:52:02
问题 When I create a JFileChooser on a system with a disconnected network drive it takes forever before the JFileChooser gets displayed. It blocks the EDT for about 20s with a single disconnected network drive. It seems like it would be a common problem, but I can't find a way to work around it. Possible options I've seen are: use JFileDialog replace FileSystemView with one where getRoots() returns a fixed list of drives switch to a WAIT cursor before trying to open JFileChooser(s) create a

NullPointerException when using WindowsFileChooserUI

此生再无相见时 提交于 2019-12-11 08:16:32
问题 I get this run-time error, i am trying to make the java file chooser look like the windows one. error code: Exception in thread "main" java.lang.NullPointerException at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:306) at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:173) at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:150) at Main.getImg(Main.java:49) at Main.main

How to save a file to a chosen directory with JFileChooser

元气小坏坏 提交于 2019-12-11 05:52:43
问题 I'm new to Java so please bear with me. In my program, I want to give the user the ability to save a file to the directory of their choice. After doing a little research, I found this nifty class called JFileChooser. What I want to do is allow the user to go to their desired directory through the JFileChooser GUI, type a name for their file, and allow them to save their file to the desired directory. I tried looking online for a solution to how to do this but almost everywhere I read, the

Use JFileChooser without using a main declaration

时光怂恿深爱的人放手 提交于 2019-12-11 05:50:04
问题 Following my previous post in this link I have another problem . Given the following code : public class GuiHandler extends javax.swing.JFrame { // GuiHandler is the class that runs the entire project // here are two private fields that I use in the code , I have more but they // irrelevant for the moment final JFileChooser openFiles = new JFileChooser(); private DataParser xmlParser = new DataParser(); // later on I have this method - XMLfilesBrowserActionPerformed private void

How to constrain JFileChooser to select particular number files?

雨燕双飞 提交于 2019-12-11 04:01:54
问题 Using JFileChooser , I have enabled multi-selection mode by setMultiSelectionEnabled(true) , but how can I set a limit so that the user can only select a particular number of text (or other) files? public File[] fileSelect() { fileChooser = new JFileChooser(); fileNameExtFilter = new FileNameExtensionFilter("Text File","txt"); fileChooser.setCurrentDirectory(new java.io.File(".")); fileChooser.setDialogTitle("Open Question Set"); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND

jfilechooser how to hide full path in folder name in DIRECTORIES_ONLY mode

回眸只為那壹抹淺笑 提交于 2019-12-11 03:08:21
问题 I have a jfilechooser set to DIRECTORIES_ONLY mode. What I do not like about my current jfilechooser is selecting folders in the directories_only mode shows the full absolute path in the folder name. Is there any way to override this behavior to just show the folder name only like in the case of a file? My jfilechooser is meant to specify a name for the folder that is about to be created to save contents to OR if a folder is selected, overwrite that folder 回答1: I am not coding in java but in

FileChooser.showOpenDialog showing default java icon on top of the frame

夙愿已清 提交于 2019-12-11 02:36:22
问题 I have created a FileChooser in my swing application. when I click on open ,the open dialog box showing default image(java) on top of the frame instead of custom image which i was set for my JFrame. Sample Code: JFileChooser filec=new JFileChooser(); int fileval=filec.showOpenDialog(myjframe); I found some times it is working fine.please help me on this. 回答1: You can set the image in the parent JFrame of the JFileChooser which will be reflected in the dialog: Image image = ImageIO.read

Selecting 'Computer' or 'Libraries' in Java's JFileChooser yields a strange File object

≡放荡痞女 提交于 2019-12-11 01:57:23
问题 I'm using JFileChooser in a very standard "Save As" situation. A am generating a file, and the user is picking where to save it. Confusingly, the user can pick number of "not real" folders. In Windows 7 they are: Computer, Network, Libraries, Homegroup. When I invoke chooser.getSelectedFile(); I get a file object, but it is very odd. It makes sense that this would be a strange File object since it doesn't correspond to a file which could actually exist. If I try to use the file, for example

JFileChooser in front of fullscreen Swing application

点点圈 提交于 2019-12-10 22:24:01
问题 I know there are some topics relative to this question (mainly this unanswered one and this one which is not handling full screen app). I basically tried every combination of first topic sample and available methods (requestFocus, requestFocusInWindow, ...) but JFileChooser is always displaying behind the fullscreen app. I tried to change filechooser's parent too (setting it to null, itself or the parent frame) with no more success. Have anyone a working example of this not-that-much