Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Filename Mask 1

Status
Not open for further replies.

HighlandJinx

Programmer
May 20, 2002
34
GB
Hi folks, this is a little annoyance that i can't seem to work out and the solution is probably really easy.

I have a "File Browser" in my current program that allows the user to search for the file they want to load, i want to be able to mask all file type and let the user only select *.txt files. Where in the code do i add the mask and how?

Thanks very much for any help you can give me.
J
 
I can remember doing this once ages ago so I can't be of much help but I can point you in the right direction I hope.

Filters (filemask) have to be set up as a separate object, just like a cellRender is a separate object to the cell and table they act on. Dig around the Java doco and look for a Filter object or similar, that should help you somewhat.

Sorry I couldn't be more helpful. ----------------------------------------
There are no onions, only magic
----------------------------------------
 
Hi HighlandJinx,
Here's some info that might be of help. The AWT class
Code:
FileDialog
has a method that excepts a
Code:
FileNameFilter
object, however the API states there is no implementation of this for Windows. I've found the easiest way to get around this is to set the filename to something like '*.txt' before showing and that will initially limit the files shown, though the user can change this to see them all.
Swings
Code:
JFileFilter
class, however, has a system to use
Code:
FileFilters
. The
Code:
JFileFilter
API has more on how to do that, here's a link:
A warning though, it's really slow if there's more than a few files to move through.

Hope this Helps,
MarsChelios
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top