Results 1 to 7 of 7
- 09-03-2009, 09:05 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
Strange JFILECHOOSER behavior on Macs with ZIP files
I have a multiplatform GUI app that is running on Macs, linux and Windows computers. I distribute a data file that is a zipped up txt file. In windows the jfilechooser has no problem selecting the zip file. However, on macs I can't select the file. The dialog box greys out the open option and displays the zip file as a folder. You can open the folder but the program isn't designed to work that. It needs the zip file which is extracts the files from and uses the files.
Here is the code. Is there a property I'm not setting to allow the user to select the zip folder on a mac?
Java Code:if (fileDialog == null) // (fileDialog is an instance variable) fileDialog = new JFileChooser(); fileDialog.setDialogTitle("Select File for Reading"); fileDialog.setSelectedFile(null); // No file is initially selected. // fileDialog. int option = fileDialog.showOpenDialog(mainFrame); // (Using "this" as a parameter to showOpenDialog() assumes that the // readFile() method is an instance method in a GUI component class.) if (option != JFileChooser.APPROVE_OPTION) return null; // User canceled or clicked the dialog's close box. File selectedFile = fileDialog.getSelectedFile();
- 09-03-2009, 09:12 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Try explicitly setting the fileSelectionMode to JFileChooser.FILES_AND_DIRECTORIES
- 09-03-2009, 09:16 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
You know I tried doing that with this line of code but the Netbeans said it wasn't correct:
I also tried:Java Code:fileDialog.FILES_AND_DIRECTORIES;
no luck doing it that way either. Do I not understand how to set that flag?Java Code:fileDialog.FILES_AND_DIRECTORIES();
- 09-03-2009, 09:22 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
P.S Refuse to write a single line of code if you don't have the API specs with you.Java Code:fileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- 09-03-2009, 09:30 PM #5
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
Yea, I just tried that and I got a strange warning but not an error:
warning "Accesssing Static Field FILES_AND_DIRECTORIES"Java Code:fileDialog.setFileSelectionMode(fileDialog.FILES_AND_DIRECTORIES);
is that okay? oh never mind. The ide suggested changing it to class reference. That seems much better. so now my code looks like your above.
I TOLD YOU IM REALLY NEW. MAJOR new. I really appreciate your time helping me today. We are a bunch of pilots and we don't program computers. I have a computer science minor from 20 years ago and I'm banging around trying to figure out Object oriented programming, learning java, and dumping my structured programming training.
I would really like to take a JAVA class. I think it would save me ...AND YOU...alot of time with some of these "simple" problems.
- 09-03-2009, 09:47 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
No need to feel bad about it.
Just make sure you have those API specs with you the same way you'd never fly without a compass.
- 09-04-2009, 02:48 AM #7
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
The warning tells you that you are accessing a static field through an instance of the class. Change
toJava Code:fileDialog.setFileSelectionMode(fileDialog.FILES_AND_DIRECTORIES);
and it will work.Java Code:fileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
The compiler gives you this warning because static fields/methods are designed to be accessed through ClassName.STATIC_FIELD; or ClassName.staticMethod(); The compiler is just telling you that you are not using the methods as it 'expects', though it is still a valid way of using them.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
Similar Threads
-
htmlparser inconsistent behavior
By sjchase in forum Advanced JavaReplies: 0Last Post: 07-21-2009, 11:07 PM -
Strange behavior with Thread.sleep()
By Steve11235 in forum Advanced JavaReplies: 16Last Post: 05-04-2009, 05:24 AM -
strange refreshing behavior
By diggitydoggz in forum New To JavaReplies: 4Last Post: 12-27-2008, 04:51 PM -
IDE for Macs
By jamesov89 in forum New To JavaReplies: 1Last Post: 09-22-2008, 06:43 PM -
Object class's equals() method behavior????
By skyineyes in forum New To JavaReplies: 4Last Post: 07-19-2008, 11:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks