How to prevent JFileChooser automatically changing to parent directory?

When you show only directories, and click on the dir icons to navigate, and then dont select anything and click OK, it automatically 'cd's to the parent folder.
My application is using the JFileChooser to let the user navigate through folders and certain details of 'foo' files in that folder are displayed in another panel.
So we dont want the chooser automatically changing dir to parent when OK is clicked. How to prevent this behavior?
I considered extending the chooser and looked at the Swing source code but it is hard to tell where the change dir is happening.
thanks,
Anil
To demonstrate this, I took the standard JFileChooserDemo from the Sun tutorial and modified it adding these lines
          // NEW line 45 in constructor
          fc.addPropertyChangeListener((PropertyChangeListener) this);
          fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      * NEW -
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     public void propertyChange(PropertyChangeEvent e) {
          String prop = e.getPropertyName();
          if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
               System.out.println("DIRECTORY_CHANGED_PROPERTY");
               File file = (File) e.getNewValue();
               System.out.println("DIRECTORY:" + file.getPath());
     }

Here is the demo:
package filechooser;
import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
* FileChooserDemo.java uses these files:
*   images/Open16.gif
*   images/Save16.gif
public class FileChooserDemo extends JPanel implements ActionListener,
          PropertyChangeListener {
     static private final String newline = "\n";
     JButton openButton, saveButton;
     JTextArea log;
     JFileChooser fc;
     public FileChooserDemo() {
          super(new BorderLayout());
          // Create the log first, because the action listeners
          // need to refer to it.
          log = new JTextArea(5, 20);
          log.setMargin(new Insets(5, 5, 5, 5));
          log.setEditable(false);
          JScrollPane logScrollPane = new JScrollPane(log);
          // Create a file chooser
          fc = new JFileChooser();
          // NEW
          fc.addPropertyChangeListener((PropertyChangeListener) this);
          fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          // Create the open button. We use the image from the JLF
          // Graphics Repository (but we extracted it from the jar).
          openButton = new JButton("Open a File...",
                    createImageIcon("images/Open16.gif"));
          openButton.addActionListener(this);
          // Create the save button. We use the image from the JLF
          // Graphics Repository (but we extracted it from the jar).
          saveButton = new JButton("Save a File...",
                    createImageIcon("images/Save16.gif"));
          saveButton.addActionListener(this);
          // For layout purposes, put the buttons in a separate panel
          JPanel buttonPanel = new JPanel(); // use FlowLayout
          buttonPanel.add(openButton);
          buttonPanel.add(saveButton);
          // Add the buttons and the log to this panel.
          add(buttonPanel, BorderLayout.PAGE_START);
          add(logScrollPane, BorderLayout.CENTER);
      * NEW -
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     public void propertyChange(PropertyChangeEvent e) {
          String prop = e.getPropertyName();
          // If the directory changed, don't show an image.
          if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
               System.out.println("DIRECTORY_CHANGED_PROPERTY");
               File file = (File) e.getNewValue();
               System.out.println("DIRECTORY:" + file.getPath());
     public void actionPerformed(ActionEvent e) {
          // Handle open button action.
          if (e.getSource() == openButton) {
               int returnVal = fc.showOpenDialog(FileChooserDemo.this);
               if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    // This is where a real application would open the file.
                    log.append("Opening: " + file.getName() + "." + newline);
               } else {
                    log.append("Open command cancelled by user." + newline);
               log.setCaretPosition(log.getDocument().getLength());
               // Handle save button action.
          } else if (e.getSource() == saveButton) {
               int returnVal = fc.showSaveDialog(FileChooserDemo.this);
               if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    // This is where a real application would save the file.
                    log.append("Saving: " + file.getName() + "." + newline);
               } else {
                    log.append("Save command cancelled by user." + newline);
               log.setCaretPosition(log.getDocument().getLength());
     /** Returns an ImageIcon, or null if the path was invalid. */
     protected static ImageIcon createImageIcon(String path) {
          java.net.URL imgURL = FileChooserDemo.class.getResource(path);
          if (imgURL != null) {
               return new ImageIcon(imgURL);
          } else {
               System.err.println("Couldn't find file: " + path);
               return null;
      * Create the GUI and show it. For thread safety, this method should be
      * invoked from the event dispatch thread.
     private static void createAndShowGUI() {
          // Create and set up the window.
          JFrame frame = new JFrame("FileChooserDemo");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          // Add content to the window.
          frame.add(new FileChooserDemo());
          // Display the window.
          frame.pack();
          frame.setVisible(true);
     public static void main(String[] args) {
          // Schedule a job for the event dispatch thread:
          // creating and showing this application's GUI.
          SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    // Turn off metal's use of bold fonts
                    UIManager.put("swing.boldMetal", Boolean.FALSE);
                    createAndShowGUI();
}

Similar Messages

  • How 2 prevent time from changing on leopard and vista?

    if i maintain successive boots into the same OS on my macbook, the time is shown correctly, whereas on booting into another OS changes the time. how to prevent this from happening?
    Neerav

    From what my brother says says about his set-up (he boots into 64 bit Vista periodically), apparently you can't. My understanding is that the two systems do a different version of time at boot, Vista uses a GMT setting in bios, and I think Mac use a local time in EFI. Anyway, the result is several hours difference between the two. I don't use Boot Camp, but I would think if you are on a network with Internet access, you should be able to have the clock reset automatically using System Prefs->Date and Time, and check the box at the top to automatically set the time from the Apple time server.
    Francine
    Francine
    Schwieder

  • Sequence file Version number. How to prevent the automatic resetting build version number whilst auto-incrementing revision number?

    Hi,
    I've got my environment set this way that each save of the sequence file increase the revision part of version number. However, during that increase the build counter is reset to 0. How to prevent it?
    TS 4.2

    Mimi,
    It is pretty common practice in software revisioning to reset a minor number to 0 when a major moves up 1.  There are many different schemes out there.  If you google or bing software versioning schemes you'll see what I'm talking about.
    So looking at it from left to right:  Major.Minor.Revision.Build = 0.0.0.1 
    if you change the Revision it would be expected that anything to the right (in this case Build) would reset to 0.  0.0.1.0!
    Let's say your version is 8.34.56.23.  It would make sense that if you were to change the Major number (which means a Major release) to 9 then your version would go to: 9.0.0.0. 
    A version number is just a unique way to tell someone which specific software you are using so it really doesn't matter that it resets to 0.  Although it makes sense because if you kept your build number sequential and didn't reset it then it would get outrageously larger which would be more annoying than anything. 
    Again this is common accepted practice in industry.
    Good Luck,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • How to prevent an automatic refresh of a dashboard

    Hi,
    Currently OBIEE automatically refreshes all reports of a dashboard once it's selected. This often causes a heavy load on our databases. The question is: how can I prevent an automatic refresh? I only want the dashboard to be refreshed once I click on the "Go" button of the dashboard prompt!
    TIA,
    Erik
    Edited by: Erik on 25-Mar-2011 12:09

    Hi Eric,
    In the dashboard, better create a landing page. In this landing page just add the dashboard object (link or image).
    Once this is configured, user have an option to navigate to the report through link.
    Even we can configure the common prompts/ global prompts at the front (Landing page) with the note to the user on navigation.
    By this way, you can have the control of dashboard refresh.
    Thanks,
    Karthikeyan V

  • How to prevent an automatic fill in of the current date into a Date/Time Field

    hi,
    maybe i checked out a strange behaviour of the adobe designer. when i put a "normal" data/time field (with no data pattern, display pattern, etc.) on a form and then change (on the pdf preview tab) to the newly designed date field,i have to stay about 2 minutes on this field not filling it out.
    after these minutes the current date is filled in automatically in the date/time field.
    what can i do preventing that? any hints?
    thanks in advance.
    markus

    I don't have any info on timelines, all I can say is check back in future versions of Acrobat :(
    Chris
    Adobe Enterprise Developer Support

  • How to prevent user from changing a field on a Form.

    I have a form and a report on the same page. The form is used to set criteria for the report. So after the criteria is entered on the form a button is clicked, which passes the criteria to the report. The form also displays some additional data based on the criteria, i.e. I do a query on the form.
    The problem I'm having is preventing the user from changing the additional data which is displayed. I tried all the wizzard options; i.e. not updatable, not insertable etc. but the user can still change the data.
    The only options seems to be writting some Java code for one of the triggers, but I haven't written any Java before.
    So I was wondering if anyone has a non-Java solution for this problem or an example of a Java program I could use to solve the problem.
    Thanks for any help
    Larry

    Hi,
    Suppose you want Empno, Sal fields of Employee table as Query only and all other fields user updateable then
    uncheck all the three check boxes
    Mandatory , Updatable , Insertable under validation options for those fields.
    When you run the form, these fields appear as text items in query mode and will appear labels once the querying done.
    Hope it works
    Madhav

  • How to prevent Finder automatically uncompressing gzipped downloads?

    Hi all,
    When I download a gzipped file (e.g. tar.gz), Finder automatically gunzips it. I find this annoying. Any way to switch this behaviour off?

    Hi, H-S T.
    You've not stated how you are downloading the files. If I presume you mean via your Web browser, and that browser is Safari, then in in the Safari > Preferences > General tab, deselect (uncheck) Open "safe" files after downloading.
    WIth Safari, this is an all-or-nothing proposition: deselect this option and no files downloaded with your browser will open automatically.
    Other browsers, such as OmniWeb., permit you to select specific applications related to types of files that you wish to consider "safe."
    If what I've outlined above does not describe your situation, please provide more details, i.e. how you are downloading the files, what browser you are using, etc.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X

  • How can i set automatic change of user status(for WBS)?

    Hi,
    Everytime when i create invoice for customer shipment using transaction code VF01, i need to change user status of WBS element manually in project to INTG in order to recognize the revenue. Is there any possiblity to change user status of WBS automatically after invoicing?
    If it is, could any one please help me to resolve this problem?

    I have Compressor 4 already, defined an own parameter set there (with 1024x680 resolution) but this was not displayed as an option in FCP X. I want to produce my resolution directly from FCP X, not produce it in another resolution and then convert it via Compressor. Let alone the fact that non of the FCP-included resolutions has a width-to-height ratio of 3:2 like mine. The solution would be to know where FCP stores its presets and to be able to modify them or add new presets.

  • How to prevent Adobe from changing Update Settings?

    Hello,
    since many years, Adobe Installer annoys me with a popup telling me "IMPORTANT: Your update options have recently changed".
    This leaves me three options and defaults to "Allow Adobe to install updates", which I do NOT want.
    I keep setting this to "Notify me to install Updates" - but after each update, the window pops up again!
    What can I do to prevent Adobe Installer from loosing its memory?
    Many thanks and kind regards
    E. Maier
    P.S. Here is the window, found somewhere on the internet:
    http://wpc.077d.edgecastcdn.net/00077D/fender/support/TSL/Flash_Update_Fender_FUSE_COMM_im ages/Flash_Update_IE4.JPG

    I caught wind of some sort of management platform they have for hosting your own internal Adobe distribution server or something.  I imagine that's their answer to this issue.  Otherwise we're all chasing after a pointless pursuit - Adobe &
    Google have what I assume is a multi-million dollar agreement to which a vocal minority of IT admins aren't going to find a way to reverse so there's no point in bothering with this since the whole structure of the arrangement is obviously designed to maximize
    Chrome penetration to the market.  Tech support may or may not know of workarounds but since any widespread workaround would go counter to the profitability of the above assumed agreement, I am certain I will be wasting my time.  It's clear to me
    the intent here is to push Chrome to millions of users via the auto-update of Flash, and so it's probably covered by the EULA as well, some kind of provision stating that if you accept auto-updating you accept 3rd party installs too. 

  • How do I allow automatic changes within apps?

    So I have Marvel Heroes, and everytime there is an update, the app wants to make changes. However, this cannot be done without an administrator password. I get the window in the picture below. Is there anyway to change settings so Marvel Heroes can update automatically?

    Where did you get the app from?

  • How do i prevent itunes to change the music directory to D:\Music

    I have all my music on a server drive. Sometimes the network has connectionproblems, that makes my drive unavailable.
    If I start up itunes, it can not find the server drive.
    The problem is that iTunes changes the standard music directory to D or C, but never changes back to de erver drive whenever it becomes available again.
    If I change it back to the server-drive and sart up itunes, itunes starts reading and updating the files in the directory, which takes up to 15 minutes, in which time I can not play any music. Eventhough all other (library)settings are within reach on that drive. No actions are possible until the library is restored.
    If my bloodpressure is still up the scale, I do not enjoy the music anymore.. it is very annoying.
    Why not display an error (drive unavailable), but keep the setting (or in a memorylist of frequently used directories) or pose question (what do you want ituens to do?)
    Same thing happens with an external drive... if the drive is not connected, and itunes is started up (to search in the store)... it changes the directory back to D or C. No actions are possible until the library is restored.

    See this migrate iTunes library post or Recover your iTunes library from your iPod or iOS device.
    tt2

  • How to prevent the automatic full-white repainting of an AWT Frame?

    Using Java 1.6.0, Windows XP, 1.6.0-b105 Client VM I have the following problem:
    I made a double buffered AWT frame. But it still flashes sometimes. It gives one flash about 6 seconds after start of application. There seems to be an incoming event "for no discernible reason". I have overridden all paint/repaint/update methods in my Frame sub class.
    These unwanted flashes are caused by the AWT painting the frame in white and then calling paint.
    I may have caught these weird calls:
    The good/normal case looks like:
    java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1206)
    at xed.xed_Frame.paint(xed_Frame.java:125)
    at xed.xed_Frame.update(xed_Frame.java:119)
    at sun.awt.RepaintArea.updateComponent(RepaintArea.java:239)
    at sun.awt.RepaintArea.paint(RepaintArea.java:216)
    at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
    at java.awt.Component.dispatchEventImpl(Component.java:4486)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    The differences in the bad case: (Not all traces of this kind cause the flashing. But after all flashes there seems to be such a trace.)
    at xed.xed_Frame.paint(xed_Frame.java:125)
    at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
    at sun.awt.RepaintArea.paint(RepaintArea.java:224)
    at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
    So how do I stop these unwanted white redraws of the Frame?

    Accidentally found the answer:
    System.setProperty("sun.awt.noerasebackground", "true");

  • How to prevent automatic display of "Server Manager" in Win Server 2008 R2

    Beginner's question:
    How to prevent the automatic loading of "Server Manager" in
    Windows Server 2008 R2 ?
    Thanks

    Task Scheduler|Library|Microsoft|Windows|Server Manager here you can disable or delete the task named
    ServerManager.
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • Can Markers (or anything else) automatically change the patch?

    I've been looking all over to try and figure out how to have MainStage automatically change to the next patch when a new Marker comes up on the backing track through PlayBack.
    Basically, when i'm playing to a backing track, i sometimes play the pads and keys on my Akai MPK49, and when a new section comes up and i need need to change my synth sound, i don;t physically have enough hands to change to the next patch. I've read a load guides, but using the AIC driver in Logic seems far too complicated and I'm getting a bit out of my depth.
    The whole point of me using markers is to identify different sections with different instruments, but I have to change between them manually anyway?
    Is there a way to have the Marker automatically change the patch? The only other way i can see of getting round this live is having a midi footswitch to automatically cycle through the patches, which means Markers are of no use to me in my 'Perform' view really.
    Any help would be amazing!

    Hi
    Currently, there is no 'super easy' way to have MS change patches automatically, and definately NOT directly from Playback markers.
    It may be possible to make use of the MIDI file 'send' capability per patch or set, routing out and back in to MS, but frankly, NOT a great workaround.
    CCT

  • Making iTunes automatically change track info of playlists

    Hello all,
    I'd like to know if there is a way to automatically change song info of all the tracks in a specific playlist.
    More specifically, I'd like to know how to make itunes automatically change the Grouping of songs as I add or remove them from any given playlist.
    Ultimately, what I'd like to be able to do is see which songs are set to sync with my iPhone and which aren't when I'm looking through my entire music library.
    Maybe there's a solution using Automator or Applescripts. I tried using smart playlists, but those seem to only be able to populate a playlist based on track info, which is the opposite of what I want to do.
    Thank you all in advance for your help,
    Scott

    I suspect iTunes is revealing "corrections" made by Windows Media Player. If so the damage is done and you'll probably find other tracks have been affected over time.
    See my post on Getting iTunes & Windows Media Player to play nicely. Most importantly uncheck the WMP options as displayed in the final image.
    tt2

Maybe you are looking for

  • Problemas no itunes

    Não consigo fazer backup do iPhone no meu computador. Aparecem as seguintes mensagens: - O SyncServer encontrou um problema e precisa ser fechado. - O MobileDeviceHelper encontrou um problema e precisa ser fechado. - O MobileBackup encontrou um probl

  • Using a LoV in each row of a report (SELECT)

    Hi everyone, I have a report of a table in APEX and I'd like to show a column with a Select list that I have saved (LoV). I mean, for each row of the table it must appear this dinamic select list. In addition, I want a button next to every Select lis

  • Problem in XML Encryption

    Hello Experts, I am trying to invoke the other platform encrypted service. I imported the public key given by the other platform so that i would be able to encrypt the request. In the receiver agreement I encrypted the request and decrypted the respo

  • Home Location

    Does any please no how to set home location on ovi maps for the Nokia 5800. Have have tried and searched everywhere but cant work out how to! For instance if i go to Drive/ Drive Home How do i set up my home location many thanks for helping stu Solve

  • Pink screen. I'm an idiot!

    I had thousands of songs on iTunes. Like an idiot I tried moving the iTunes folder to an external hard drive then back again thinking I was running out of HD space (which I was not). Now my iTunes interface is pink and I cannot find most of my music.