In view of the recent problems encountered with JFileChooser in the project, here is a summary
1. Regarding the filters that need to be used to display files of a certain format type, the key codes posted below are for reference
public class FileUtil extends javax.swing.filechooser.FileFilter{
public boolean accept(java.io.File f) {
if (f.isDirectory())
return true;
return f.getName().endsWith(".dcm"); //Set to select files suffixed with .dcm
}
public String getDescription(){
return ".dcm";
}
public static void main(String[] args){
FileUtil fileFilter=new FileUtil();
JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(fileFilter);
jfc.setFileSelectionMode(JFileChooser.APPROVE_OPTION);
jfc.setSize(500, 400);
jfc.setLocation(w, h);
jfc.showDialog(new JLabel(), "选择");
File file = jfc.getSelectedFile();
String filepath = file.getAbsolutePath();
if (filepath != null && filepath.length() !=0 &&filepath.endsWith(".dcm")) {
// System.out.println("打开的路径是"+filepath);
mainFrame.renewImagePanel(2,filepath);
}else{
new MessageDialog("Please select a picture in dcm format!");
logger.info("No picture has been selected");
}
}
}
2. About the style of UIManager
Determines the current style sense based on the style of the native system
try {
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
} catch (Exception e) {
e.printStackTrace();
}