Clicking in empty area in JFileChooser selects the closest file

Hi,

I came across this behavior of JFileChooser that whenever the user clicks in an empty area within the file chooser window, the selection is set to the closest file or directory. Is there any way to configure JFileChooser that a file will be selected only if the user directly clicks on it? Clicking on empty area should preferably deselect the current selection. I am working with 1.5.0_01. This is the code I was working on:

import java.io.File;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

public class FileFilterDemo {

public FileFilterDemo() {

}

public static void main(String[] args) {

JFileChooser chooser = new JFileChooser();

chooser.setCurrentDirectory(new File("."));

chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

public boolean accept(File f) {

return f.getName().toLowerCase().endsWith(".gif")

|| f.isDirectory();

}

public String getDescription() {

return "GIF Images";

}

});

int r = chooser.showOpenDialog(new JFrame());

if (r == JFileChooser.APPROVE_OPTION) {

String name = chooser.getSelectedFile().getName();

System.out.println(name);

}

}

}

Thanks

[1274 byte] By [jc36a] at [2007-11-27 1:33:50]
# 1
Use [url http://forum.java.sun.com/help.jspa?sec=formatting]code formatting[/url] when posting code.Works fine on Windows XP with 1.5.0_11
Rodney_McKaya at 2007-7-12 0:40:26 > top of Java-index,Desktop,Core GUI APIs...
# 2
HeyOn my pc (Win xp with 1.6.0) it works like you wanted.If i click on empty area nothing is selectedSatanduvel
Satanduvela at 2007-7-12 0:40:26 > top of Java-index,Desktop,Core GUI APIs...