Solved

disable input of text in a Jfilechooser

Posted on 2004-04-21
18
1,414 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to parse custom JSON to POJO java 4 72
ArrayIndexOutOfBoundException 9 80
HashTable highest marks enumeration alternative 9 37
CSV file parsing thru Java 13 26
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

813 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

9 Experts available now in Live!

Get 1:1 Help Now