Link to home
Start Free TrialLog in
Avatar of monjoes
monjoes

asked on

disable input of text in a Jfilechooser

Dear all,
We have passed in the filename to a JFileChooser so that it display the filename we want, does anyone know how to block the user from changing the filename or to block the input?

Thanks
Joey
Avatar of mmuruganandam
mmuruganandam
Flag of United States of America image

You have to write your own file chooser then.  I don't think, there is a direct way to do that.  Anyway, let me check if there is any way


Regards,
Muruga
Avatar of sciuriware
sciuriware

There is a reason (for SUN) to always enable user input: you can't choose a root (e.g. C:\)
without typing.
If you don't want the user to change the preset, why not compare the selection against the preset?
;JOOP!
>> you can't choose a root

You can select it by browing thru the available list in the filechooser.
Avatar of monjoes

ASKER

Thanks Sciuriware,
But we don't want the user to change the text at all.
All you can do is set the edit field to non editable.
But you can't access that component.
Remain 2 options: indeed write your own chooser based on JDialog (not so difficult as it seems),
                           add actionlisteners and find out which one reports an edit attempt so you can reset it.
;JOOP!
Already given options ;)
Avatar of zzynx
Maybe interesting: "Customizing JFileChooser": http://java.sun.com/developer/JDCTechTips/2004/tt0316.html

There must be a way to get (and disable) that filename TextField...
>> But we don't want the user to change the text at all

Then why do you want to use the JFileChooser in the first place? It is a file-chooser -> mean to choose files - and you don't want to do that. When you already have the file-name with you, just use it. Why to display the JFileChooser?
Avatar of monjoes

ASKER

Just let them to choose the path
Then you need to set it so that it only allows to choose directories
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This will filter out the directory only listing or file only or both.

It is nothing to do with the Text field.
monjoes, what you need is a JFileChooser with the setting above (DIRECTORIES_ONLY)
and with a file filter that only accepts a directory with the file in it that you want.
It's easier for you NOT to put the filename in the chooser but on a label above it.
;JOOP!
Since at last it became clear that the author wanted to use the JFileChooser
>> Just let them to choose the path
I think my comment
>> Then you need to set it so that it only allows to choose directories
  (+explanation how to do that in the following comment)
is a valid candidate for the accepted answer.