-
Bug
-
Resolution: Fixed
-
P3
-
1.2.2
-
beta
-
generic
-
generic
Name: vi73552 Date: 06/30/99
//JFileChooser.setApproveButtonToolTipText() corrupts the object
//If you run this program, the text on button is "Install";
//If you un-commented out two commented lines, the text on button is
// "Open"
import java.util.*;
import java.text.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class Test {
public Test() {
Frame frame = null;
JFileChooser chooser = new JFileChooser();
MyFileFilter filter = new MyFileFilter("jar", "jar files");
chooser.setFileFilter(filter);
chooser.setDialogTitle("Install Beans");
chooser.setApproveButtonText("Install");
// chooser.setApproveButtonToolTipText("Install");
// chooser.setApproveButtonMnemonic('\0');
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
int retval = chooser.showOpenDialog(frame);
if(retval == 0) {
File theFile = chooser.getSelectedFile();
if(theFile != null) {
JOptionPane.showMessageDialog(frame, "You chose this file: " +
theFile.getAbsolutePath());
}
}
}
public static void main(String[] args) throws Exception {
new Test();
}
public class MyFileFilter extends javax.swing.filechooser.FileFilter {
private String description = null;
private String extension = null;
public MyFileFilter(String extension, String description) {
this.extension = extension;
this.description = description;
}
public boolean accept(File f) {
if(f != null) {
if(f.isDirectory()) {
return true;
}
if(extension.equalsIgnoreCase(getExtension(f)))
return true;
}
return false;
}
public String getDescription() {
return description;
}
public String getExtension(File f) {
if(f != null) {
String filename = f.getName();
int i = filename.lastIndexOf('.');
if(i>0 && i<filename.length()-1) {
return filename.substring(i+1);
};
}
return null;
}
}
}
(Review ID: 53344)
======================================================================