-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.2.0
-
None
-
generic
-
solaris_2.6
There are a couple of problems in JFileChooser:
1) The directory field "Look in:" in JFileChooser never get updated during file navigation.
2) JFileChooser doesn't validate the file name which are entered in "File Name" field by user - This is unacceptable, there should be a message to warn user that the file doesn't exist.
The following test demonstates the problems:
import java.awt.swing.*;
import java.awt.swing.preview.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TestFileChooser extends JFrame
implements ActionListener
{ public TestFileChooser()
{ JMenuBar mbar = new JMenuBar();
JMenu m = new JMenu("File");
JMenuItem m1 = new JMenuItem("Open");
m1.addActionListener(this);
m.add(m1);
JMenuItem m2 = new JMenuItem("Exit");
m2.addActionListener(this);
m.add(m2);
mbar.add(m);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add("North", mbar);
setContentPane(p);
}
public void actionPerformed(ActionEvent evt)
{ String arg = evt.getActionCommand();
if (arg.equals("Open"))
{ JFileChooser d = new JFileChooser();
d.showDialog(this);
}
else if(arg.equals("Exit")) System.exit(0);
}
public static void main(String args[])
{ JFrame frame = new TestFileChooser();
frame.pack();
// comment out the line below to see the menu bug
frame.setSize(300, 400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0); }
} );
}
}
1) The directory field "Look in:" in JFileChooser never get updated during file navigation.
2) JFileChooser doesn't validate the file name which are entered in "File Name" field by user - This is unacceptable, there should be a message to warn user that the file doesn't exist.
The following test demonstates the problems:
import java.awt.swing.*;
import java.awt.swing.preview.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TestFileChooser extends JFrame
implements ActionListener
{ public TestFileChooser()
{ JMenuBar mbar = new JMenuBar();
JMenu m = new JMenu("File");
JMenuItem m1 = new JMenuItem("Open");
m1.addActionListener(this);
m.add(m1);
JMenuItem m2 = new JMenuItem("Exit");
m2.addActionListener(this);
m.add(m2);
mbar.add(m);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add("North", mbar);
setContentPane(p);
}
public void actionPerformed(ActionEvent evt)
{ String arg = evt.getActionCommand();
if (arg.equals("Open"))
{ JFileChooser d = new JFileChooser();
d.showDialog(this);
}
else if(arg.equals("Exit")) System.exit(0);
}
public static void main(String args[])
{ JFrame frame = new TestFileChooser();
frame.pack();
// comment out the line below to see the menu bug
frame.setSize(300, 400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0); }
} );
}
}
- duplicates
-
JDK-4401437 JFileChooser doesn't validate [characters in] filenames
-
- Closed
-
- relates to
-
JDK-6215240 JFileChooser should provide API to control what happens when opening a non-existant file.
-
- Closed
-