Solved

disable input of text in a Jfilechooser

Posted on 2004-04-21
18
1,390 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:monjoes
  • 4
  • 4
  • 3
  • +3
18 Comments
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10885886
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
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 10885940
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!
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10885948
>> you can't choose a root

You can select it by browing thru the available list in the filechooser.
0
 

Author Comment

by:monjoes
ID: 10885952
Thanks Sciuriware,
But we don't want the user to change the text at all.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 10886075
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!
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10886102
Already given options ;)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10886323
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...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:Mayank S
ID: 10887564
>> 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?
0
 

Author Comment

by:monjoes
ID: 10887576
Just let them to choose the path
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10887631
Then you need to set it so that it only allows to choose directories
0
 
LVL 37

Accepted Solution

by:
zzynx earned 125 total points
ID: 10887642
setFileSelectionMode(int mode)

mode - the type of files to be displayed:
JFileChooser.FILES_ONLY
JFileChooser.DIRECTORIES_ONLY  <<<<<<<<<<<<<<<<<<<<<<
JFileChooser.FILES_AND_DIRECTORIES
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10887658
This will filter out the directory only listing or file only or both.

It is nothing to do with the Text field.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 10887670
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!
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10889308
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11676737
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now