?
Solved

disable input of text in a Jfilechooser

Posted on 2004-04-21
18
Medium Priority
?
1,522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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
 
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 500 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

741 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