jfilechooser

jFileChooser to save file of selected tab

馋奶兔 提交于 2020-01-25 19:19:53
问题 Ok so I have a text editor made that can so far create new files and open files using jFileChooser. What I am trying to do is get the saving of files to work. Everytime you add or open a few file it adds a new tab to the tabbedpane and the name will be either file 1 etc or the name of the file opened. When you click the save button the save dialog opens up int returnVal = fileChooser.showSaveDialog(this); I want the name on the tab to be inserted to the name of file field. Also how do I make

JFileChooser(showSaveDialog) cant get the value of the extension file chosen

依然范特西╮ 提交于 2020-01-17 15:40:09
问题 Im making a desktop application and it has a JFileChooser(ShowSaveDialog) function.. When I tried to save a sample text file the program didnt get the extension file that I chose.. I'm trying to use the if else or switch statement and I cant figure it out what command will I use to get the string/Int value for the condition if pdf,word or txt extension is chosen as file extension... public class Save { static boolean flag = false; public static void main(String[] args) throws IOException,

Use a thread to wait until the user has picked a file

蓝咒 提交于 2020-01-16 14:35:06
问题 I have a mainClass in Java, that starts a GUI in swing. I ask the user to open a file using a JFileChooser. I want the main to wait until the user has finished picking the file and then continue with the rest of the code in main. How do I do this using threads? Thanks in advance. Here is the skeleton code: public class MainClass { public static void main(String[] args) { GUI gui= new GUI(); //wait for user input here //Continue with code System.out.println("User has picked a file"); } } GUI

Java JFilechooser customization

风格不统一 提交于 2020-01-16 02:56:09
问题 further to my question Java JFilechooser. It was suggested to extend BasicFileChooserUI, overriding create/getModel and providing an implementation of BasicDirectoryModel. I attempted this however, I could not achieve it. JFileChooser does not have a setUI method. So your only choice is to override getUI. JFileChooser blah = new JFileChooser() { CustomFileChooserUI asdf = null; /** * */ private static final long serialVersionUID = 1L; public FileChooserUI getUI() { if (asdf == null) { asdf =

How to pre-populate a JFileChooser will “filename”?

六月ゝ 毕业季﹏ 提交于 2020-01-15 06:17:29
问题 I intend to populate a JFileChooser with names from a database but use the standard JFileChooser Dialog for load, delete, save and save-as. I want to give users an impression that they are working on a file system whereas am using a database at the backend to save changes. The user should not be able to browse to a different directory to save or save as. I want to use the same JFileChooser Dialog but with a cancel button and another button(delete|save|save as|load). 回答1: Can't be done using

JFileChooser for directories on the Mac: how to make it not suck?

爱⌒轻易说出口 提交于 2020-01-12 05:26:06
问题 The JFileChooser in "directories only" mode on the Mac has two serious, crippling problems: 1) You cannot create directories with it 2) You cannot switch drives This is rather a huge problem for my installer app. As far as I can tell, Apple provides no way around this problem, you can't even activate the non-native directory chooser ... so the only alternative is to find a free/open source pure-Java replacement widget. Does anybody know of one? 回答1: What about using java.awt.FileDialog? It

How do you put the mouse cursor over the OPEN button on a JFileChooser?

假如想象 提交于 2020-01-06 04:45:50
问题 I'm trying to snap my mouse cursor over the approve button by default on a JFileChooser but I cannot find any examples anywhere where this has been done before. I have tried using hard coded x,y positions but this is useless when I run my application on a different pc. Any help would be appreciated, my code is as follows: FileOpenDialog fileChooser = new FileOpenDialog(index); fileChooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { } }); /

How do I make JFileChooser open in the current directory the user is in?

拜拜、爱过 提交于 2020-01-05 10:26:42
问题 I do not want to specify a directory. I just want it to automatically "know" and open in the directory the user is working in. How do I do this? 回答1: This examples defaults to the user.dir on first showing. It then retains the instance of the chooser to automatically track the last load or save location, as suggested by MadProgrammer. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.io.*; public class ChooserInCurrentDir { //

JFileChooser causes log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace)

£可爱£侵袭症+ 提交于 2020-01-05 08:22:11
问题 Searching for a solution to a problem I am having with JFileChooser. It is the exact same problem as the one found here: https://forums.oracle.com/thread/2532293. If someone could give me a solution and explanation for the error that would be awesome. 来源: https://stackoverflow.com/questions/18091407/jfilechooser-causes-log4cpluserror-no-appenders-could-be-found-for-logger-adsy

File renameTo does not work

邮差的信 提交于 2020-01-02 02:22:06
问题 I am trying to add an extension to the name of file selected by a JFileChooser although I can't get it to work. This is the code : final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); String name =f.getAbsoluteFile()+".txt"; f.renameTo(new File(name)); FileWriter fstream; try { fstream = new FileWriter(f); BufferedWriter out =