Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to expand a JFileChooser directory without a mouse

Using a JFileChooser, I can select a directory by double clicking the directory (going down a level) with my mouse. Is there a way to select a directory without the mouse? For example, is there a key binding to go down a directory level or do I have to somehow add a key listener to the JFileChooser?

like image 526
splatek Avatar asked Oct 24 '22 02:10

splatek


1 Answers

You should be able to use tab to move between the different parts of the chooser, and then use the arrow keys to change which directory is highlighted, and then press Enter to change the directory to the highlighted one.

I have tested the following example code on my machine (Vista/JDK 1.6) and it works as I would expect:

import javax.swing.*;
public class test {
  public static void main(String[] args) {
      (new JFileChooser("")).showOpenDialog(new JFrame());
      System.out.println("OK!");
   }
}

If your project is not responding similiarly in your JFileChooser, I would debug as follows:

  1. Create test.java with only the code necessary to pop up a chooser.
  2. If the test app differently than within your app, its something in your code causing it to fail, such as UI skinning code, keyboard listeners, etc. Modify the example, one change at a time to closer replicate your settings for your chooser in your app and see if you can pinpoint where it breaks.
  3. If even a basic test app doesn't work right, it is probably something about your setup, such as a bug in your JDK version, your OS, etc. Troubleshoot your setup.
like image 163
Jessica Brown Avatar answered Nov 15 '22 00:11

Jessica Brown