Solved

disable input of text in a Jfilechooser

Posted on 2004-04-21
18
1,486 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

728 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