0

Rookie Java programmer with a (hopefully) simple question. I'm trying to get the standard JFileChooser to default to the detail view instead of list.

I found this thread that had what I believe is a good answer:

How can I start the JFileChooser in the Details view?

Specifically:

JFrame frame = new JFrame();
JFileChooser  fileChooser = new JFileChooser(".");
Action details = fileChooser.getActionMap().get("viewTypeDetails");
details.actionPerformed(null);
fileChooser.showOpenDialog(frame);

But when I implemented it into my program, the compiler says that it cannot find the Action and details symbols. I'm thinking the person who answered this question meant for those to be generic placeholders, but I'm not sure what to put in there instead? Thank you and please let me know if you need any other info!

3
  • the compiler says that it cannot find the Action - "Action" is a class in the JDK. "details" is the variable to reference the Action from the ActionMap. You are missing an import statement for the Action class. Read the API to find out which package the Action class is found. Or you can read the section from the Swing tutorial on How to Use Actions to better understand how Actons work. The ActionDemo from the tutorial will show the import statements needed.
    – camickr
    Mar 1, 2016 at 22:02
  • I read the API and included import java.awt.*; and import java.awt.event.*; But I still have the same problem? Thanks for the help! Mar 1, 2016 at 22:37
  • The Action interface is not in either of those packages. You need to learn how to read the API. The API contains the classes of the JDK and the method of every class. The package is right on the top of the page when you click on the Action link of the API. Check again. If you don't have it bookmarked then here is the online link to the API: docs.oracle.com/javase/8/docs/api/…. Just find the Action class. There are actually two, so you will need to use the appropriate one, which will be obvious if you click on both links.
    – camickr
    Mar 1, 2016 at 22:43

1 Answer 1

0

Rookie mistake. (Which makes sense because I'm green as grass.) Needed to add

import javax.swing.*;

to use the Action class. Thank you to camickr (see comments above) for advice on finding the solution!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.