I think of two possible reasons for something like this:
- Are you trying to connect the AWT and Swing GUI in the same program or
- You are trying to mix a console program (that is, using System.out.println (...) and get input through a Scanner object) with the Swing GUI.
If you do one of these two things, then you should simplify and make it only a program like the Swing GUI. If this information does not help, you can provide us with more information about your problem.
Change 1
I just noticed the details of your code. The following is a new part of JPanel ():
int retValue = fc.showOpenDialog(new JPanel());
To make JFileChooser act as a dialog to your top-level window (which it does not currently do and which is your main problem), you must pass a component that is in the parent's top-level window, for example, JPanel or JButton, which is stored inside your jframe or japplet.
Edit 2
Well, you're trying to mix a Java console program with a Swing GUI program that looks like ice cream with pickles — they just don't mix with each other. There is no top-level window offering the JFileChooser showOpenDialog method to act as a true dialog.
The best solution is not to do this, instead rewrite the application into the full Swing GUI.
Hovercraft full of eels
source share