Name: gm110360 Date: 07/21/2004
Steps to reproduce:
1. Compile and run the testcase provided
javac -d . DialogTest.java
java an.bn.DialogTest
2. Press the button "Open the File" to bring up the JFileChooser Dialog
3. Move to a directory so that there are more than one directory visible in the JFileChooser.
4. Press the DETAIL button and select a directory
5. Now press <enter> and notice that the focus is moving to the next directory rather than opening up the selected directory.
Also notice that sometimes, horizontal scrolling is taking place when we keep on pressing <enter> key.
Testcase:
DialogTest.java
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.util.StringTokenizer;
public class DialogTest extends JFrame {
static private final String newline = "\n";
JFileChooser fc = null;
public DialogTest() {
super("FileChooserDemo");
//Create the log first, because the action listeners
//need to refer to it.
//Create a file chooser
fc = new JFileChooser();
fc.setMultiSelectionEnabled(true);
TextFilter txt = new TextFilter();
fc.setFileFilter(txt);
fc.addChoosableFileFilter(txt);
fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
//Create the open button
JButton openButton = new JButton("Open a File...");
openButton.setMnemonic(openButton.getText().charAt(0));
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
//System.out.println("Approved " + newline);
File[] selectedFiles = fc.getSelectedFiles();
for ( int i=0; i < selectedFiles.length; i++)
System.out.println(" Files Selected:"
+ selectedFiles[i].toString());
}
else {
System.out.println("Open command cancelled by user."
+ newline);
}
//fc.setSelectedFile(new File(""));
}
});
//For layout purposes, put the buttons in a separate panel
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(openButton);
//Add the buttons and the log to the frame
Container contentPane = getContentPane();
contentPane.add(buttonPanel);
}
public static void main(String[] args) {
StringBuffer tm=new StringBuffer("\"");
tm.append("THis is new");
tm.append("\"");
System.out.println(tm);
try {
System.out.println("LookAndFeel Selected is "
+ UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
System.out.println("An exception is raised by UIManager.setLookAndFeel\n");
}
JFrame frame = new DialogTest();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
class TextFilter extends javax.swing.filechooser.FileFilter
{
public boolean accept(File f)
{
if ( f.isDirectory() || f.getName().endsWith("txt") ||
f.getName().endsWith("TXT") )
return true;
else
return false;
}
public String getDescription()
{
return "Text Files";
}
}
}
(Incident Review ID: 208998)
======================================================================