0
JMenuItem mntmLoad = new JMenuItem("Load");
        mntmLoad.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                JFileChooser chooser = new JFileChooser();
                chooser.setMultiSelectionEnabled(true);
                int option = chooser.showOpenDialog(testgui.this);
                if (option == JFileChooser.APPROVE_OPTION) {
                  File[] sf = chooser.getSelectedFiles();
                  String filelist = "nothing";
                  if (sf.length > 0) filelist = sf[0].getName();
                  for (int i = 1; i < sf.length; i++) {
                    filelist += ", " + sf[i].getName();
                  }
                  statusbar.setText("You chose " + filelist);
                }
                else {
                  statusbar.setText("You canceled.");
                }
                }
        });
        mnFile.add(mntmLoad);

the compiler show error on this line(The method showOpenDialog(Component) in the type JFileChooser is not applicable for the arguments (testgui))

int option = chooser.showOpenDialog(testgui.this);

any idea?

Edited by sing1006

2
Contributors
2
Replies
10
Views
3 Years
Discussion Span
Last Post by sing1006
1

You didn't post the declaration of testgui, but apparently it's not a subclass of Component. The ".this" is even more mysterious.

Edited by JamesCherrill

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.