ycomp
asked on
Using JFileChooser
Hi,
I do not do GUI programming in Java. However, I have a simple class that I run all the time (it simply spits output to System.out) but it works on different files.
I want to implement the ability to choose a file from the file system.
I found some code on JFileChooser at:
http://java.sun.com/j2se/1.3/docs/api/javax/swing/JFileChooser.html
but it won't compile because it requires some parent "Component" object. I think maybe I need to create AWT somehow. But I know nothing about AWT.
So if someone could please show me some code that can open a file from the file system from a regular java class then it would help me a lot.
Actually I would prefer to use the Windows Open File Dialog but I suspect that is more difficult to do. But if you know how to use that instead of JFileChooser then feel free to demonstrate that approach. Otherwise I would be happy to know how JFileChooser works.
thanks!
I do not do GUI programming in Java. However, I have a simple class that I run all the time (it simply spits output to System.out) but it works on different files.
I want to implement the ability to choose a file from the file system.
I found some code on JFileChooser at:
http://java.sun.com/j2se/1.3/docs/api/javax/swing/JFileChooser.html
but it won't compile because it requires some parent "Component" object. I think maybe I need to create AWT somehow. But I know nothing about AWT.
So if someone could please show me some code that can open a file from the file system from a regular java class then it would help me a lot.
Actually I would prefer to use the Windows Open File Dialog but I suspect that is more difficult to do. But if you know how to use that instead of JFileChooser then feel free to demonstrate that approach. Otherwise I would be happy to know how JFileChooser works.
thanks!
JFileChooser will be similar to the Windows Open dialog. Calling this would involve some JNI programming, which I think is more complex than you want.
Where are you calling from? It would be pretty unusual to open a dialog from a CLI, so I assume there is some application at work here. Is this AWT/Swing, or a web app?
I got the demo to work (with a warning - it is looking for a file that doesn't exist on my FS). What error do you get if you run the demo source directly? (You are on JDK 1.4.x?)
Where are you calling from? It would be pretty unusual to open a dialog from a CLI, so I assume there is some application at work here. Is this AWT/Swing, or a web app?
I got the demo to work (with a warning - it is looking for a file that doesn't exist on my FS). What error do you get if you run the demo source directly? (You are on JDK 1.4.x?)
ASKER
I couldn't get it to run because I didn't know what a Compoonent Class was (the parent object it uses as a parameter).
JFileChooser is ok if Windows Open is too difficult. I just need to select a file.
I just have a normal java app. there is no gui stuff in it. No AWT/Swing, etc. It is just a test app that tests part of the library I'm building. I also know nothing about AWT, Swing, etc.
I am using JDK 1.3.1
JFileChooser is ok if Windows Open is too difficult. I just need to select a file.
I just have a normal java app. there is no gui stuff in it. No AWT/Swing, etc. It is just a test app that tests part of the library I'm building. I also know nothing about AWT, Swing, etc.
I am using JDK 1.3.1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cool, exactly what I wanted. Thanks!
http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html