my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes JFileChooser - How to set imput focus. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFileChooser - How to set imput focus." Watch "JFileChooser - How to set imput focus." New topic
Author

JFileChooser - How to set imput focus.

Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I'm using JFileChooser to select files that already exist. I'd like the imput focus to be on the displayed list of files so that the user may immediately select one of more of the listed files but when the filechooser is displayed the input focus is in the text box. How may the input focus be specified?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you may need to explain this a bit more, as-is it makes little sense to me.

if I open a fileChooser with a list of files displayed to select from,
I'll use the mouse to select those file/s, so the focus could be anywhere
and it won't make any difference once I click on the first file
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
Michael Dunn wrote:
if I open a fileChooser with a list of files displayed to select from,
I'll use the mouse to select those file/s, so the focus could be anywhere
and it won't make any difference once I click on the first file


The user will NEVER type in a file name but will probably want to click on a file or select multiple files. The first file is automatically selected and I'd like to skip that first mouse click. The app will work without it but it's a small attention to detail.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this seems to be an unresolved issue with fileChoosers.

you can set it so the textfield (showing selected file) cannot have the focus,
but focus then goes to the look-in comboBox, so that's no good for you.

you may need to dig into the fileChooser source code to find the component
that displays the folder/file names (I think it's a JTable) and set the selection
of the automatically-selected first file
Antonio Principato
Greenhorn

Joined: May 21, 2012
Posts: 10
Also you could load all of the files into a JComboBox that way they have to choose from the list?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JFileChooser - How to set imput focus.
 
Similar Threads
problem with filefilter for jfilechooser
How the applet can open a finle like JFileChooser?
JfileChooser to open a file
JFile Chooser Sorting
JFileChooser