• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Open Dialog JFileChooser

 
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay again I have this same project and Im trying to get the Open and save dialog boxes to show when the user clicks the appropriate menu item.

I have seen the example on Sun's website, but the menu action listener is another class then the one that implements the gui.

I get the error
JFileChooser cannot be applied to UNTFgui.
on this line of code
int returnVal = fc.showOpenDialog(UNTFgui.this);


 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried passing in "null" as the parameter to showOpenDialog, like the javadocs suggest?
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only use an instance of Component or a subclass, and your UNTFgui class does not meet that requirement.

So either you have to create a component (like a applet, frame or panel), or just use null as Ulf said.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I use null will the file I open still open up inside the appropriate textArea?
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also how in the world do I add a filter so it will only open up a certain file extension. I have read through the Java Tutorial and it does not help, I have also looked at the API.
 
Rob Spoor
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can also perform slightly other checks; use "name.regionMatches(true, name.length - 4, ".txt", 0, 4)" to check while ignoring the case.

There is one draw back: when saving, JFileChooser allows any typed in value. If that value does not include the correct extension, it is not added automatically but you have to do it yourself.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the "public void addChoosableFileFilter (FileFilter filter)" method? It would seem to do what you're asking.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright! I got it to work, even on a separate file!. Now I just have to have it actually read and write the file. Yah!
    Bookmark Topic Watch Topic
  • New Topic