Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser - How to set imput focus.

 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you could load all of the files into a JComboBox that way they have to choose from the list?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic