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


I do not want to specify a directory. I want it to automatically open "Address" and in the directory that the user is working on. How do i do this

This example is the default for user.dir on first showing. After this, as suggested by Madprogrammers, automatically maintains the example of those who choose to track past loads or save space.

Enter image details here

  Import java.awt. *; Import java.awt.event. *; Import javax.swing *; Import javax.swing.border.EmptyBorder; Import java.io * *; JPanel GUI = new JPanel (new border layout ()) seen by the public class ChooserInCurrentDir {/ / GUI (without the frame); Choose JFileChooser File; Private JTextArea output = new JTextArea (10, 40); Choser Incident Dior () {initComponents (); } Public final zero initComponents () {gui.setBorder (new blank border (2, 3, 2, 3)); String userradial cation = system.jetproperty ("user directory"); File userDir = new file (userDirLocation); // default in user directory file = new jefilclosure (userer); Action Open = New Object Action ("Open") {@ Override Public Voice Action Crore (Action Event E) {Int. Results = File Changer. Show Open Dialog (GUI); If (Results == JFileChooser.APPROVE_OPTION) {try {file f = fileChooser.getSelectedFile (); FileReader fr = New FileReader (f); Output. Reed (FR, F); Fr.close (); } Hold (Exception pre) {ex.printStackTrace (); }}}}; Action Save = New Object Action ("Save ') {@ Override Public Voed Action Perffered (Action Event e) {Intimate Results = File Chose. Showwave Dialogue (GUI); New Unsupported Operation Exception (" Not yet supported. ");} }; JToolBar TB = new JToolBar (); Gui.add (TB, Border Layout. PAGE_START); tb.add (open); tb.add (save); output.setWrapStyleWord (true); output.setLineWrap (true ); Gui.add (new JScrollPane (Output, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER))}} Public Finish JComponent getGui () {Return GUI;} Public Stable Zero Main (String [] Args) {Runnabal R = New Runnabal () {@ Override Public Wide Run) (Chuosar Incident Dior cicd = new ChooserInCurrentDir (); Jeff Fr F = New JFram ("Current Selector in Selector" ); F.add (cicd.getGui ()); // ensures that the JVM is closed after closing the frame and // ends all non-daemon threads f.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE); // http://stackoverflow.com/a/7143398/418556 for demo see f.setLocationByPlatform (right); // ensures that the frame is the minimum size that it needs to be // It displays the components in its order; f.pack (); // should be finalized, shimmer, run, // to avoid resizing artifacts. F.setVisible (true); }}; // swing GUI should be made on ADT // http://docs.oracle.com/javase/tutorial/uiswing/concurrency and SwingUtilities.invokeLater (r); }}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -