Solved

disable input of text in a Jfilechooser

Posted on 2004-04-21
18
1,364 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
Comment Utility
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
Comment Utility
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
Comment Utility
>> you can't choose a root

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

Author Comment

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

Expert Comment

by:sciuriware
Comment Utility
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
Comment Utility
Already given options ;)
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> 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
Comment Utility
Just let them to choose the path
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

771 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

14 Experts available now in Live!

Get 1:1 Help Now