You go to great trouble to display a JFileChooser and allow the user to select a file. But then you don't pay any attention to what file the user selected, and instead you create an image from no file at all:
You'll need to provide the path which the user selected here.
Secondly, you go to far too much trouble with that JFileChooser code. Here's your code which is complicated and doesn't always work properly:
That is only going to work on Windows systems (other systems use / to separate entries in the file path) and, more importantly, it will only work if the user chose a file from the file chooser's default directory. (At least I think that's right -- the documentation doesn't say what the "current directory" of a JFileChooser is.) Here's some code which is both simpler and more reliable:
You don't need to change the path to all lower-case either. That's another thing which is Windows-only and will fail on other operating systems, but you don't even need to do it on Windows systems.
posted 9 years ago
Still I am not able to import any image on pane using FileChooser. Please help me.