I have a minimum Java Swing App to show the problem : when I opened a JFileChooser and tried to double click on a file on the right side column, it will try to move to the left column, no matter how fast I double clik on it, it won't be selected, until it's in the left column position, is this a bug in Java Swing, or am I doing something wrong ? How to fix it ?
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.filechooser.FileFilter;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class Demo_File_Chooser_Show_Txt_Only extends JFrame
{
private JButton buttonBrowse;
public Demo_File_Chooser_Show_Txt_Only()
{
super("Demo File Type Filter");
setLayout(new FlowLayout());
buttonBrowse=new JButton("Browse...");
buttonBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { showOpenFileDialog(); } });
getContentPane().add(buttonBrowse);
setSize(300,100);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
catch (Exception e) { }
SwingUtilities.invokeLater(new Runnable() { public void run() { new Demo_File_Chooser_Show_Txt_Only(); } });
}
private void showOpenFileDialog()
{
JFileChooser fileChooser=new JFileChooser(".");
fileChooser.setControlButtonsAreShown(false);
fileChooser.setFileFilter(new FileFilter()
{
@Override
public boolean accept(File file) { return file.getName().toLowerCase().endsWith(".txt"); }
@Override
public String getDescription() { return ".txt files"; }
});
// fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.showOpenDialog(null);
}
}