1

I need an Open Dialog File Chooser that opens files for reading only. I want user to only be able to click on a file name to select it with no option to edit the name. Users should be able to browse to other folders, though.

I'm on Ubuntu 10.11 with the latest Java (as of January).

TIA.

Nate Lockwood
  • 3,325
  • 6
  • 28
  • 34

1 Answers1

1

This example shows that editable file names is a feature of the FileChooserUI implementation. For example, com.apple.laf.AquaFileChooserUI does not have this capability. The tutorial does not suggest any way that it can be changed, but this FileBrowser may suggest a custom alternative.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I see that I can add an action listener and can check that the file exists. If it doesn't exist is it possible to prevent the file chooser from returning? – Nate Lockwood Apr 13 '12 at 15:33
  • After the action listener detects that the file does not exist adding "theFileChooser.cancelSelection();" causes it to quit as though the user had canceled. I would rather have the File Chooser stay open and give the user another chance but ... – Nate Lockwood Apr 13 '12 at 15:53
  • I'm not sure I understand what you're doing. If you edit your question to include an [sscce](http://sscce.org/) I'll take a look. – trashgod Apr 13 '12 at 16:40
  • What I want to do is keep the user from clicking on "Open" if the editable text box "File Name" has been edited since I cannot prevent edits. I now don't think it may easily be done. I can intercept the "Open" click and check that the file exists (also has the correct permissions) and force a Cancel if not; so that's what I'll do. Thanks for your help. – Nate Lockwood Apr 16 '12 at 19:30
  • Sounds reasonable; don't hesitate to update the question or pose an alternate answer going forward. – trashgod Apr 17 '12 at 01:12