나는 버튼이있어서 JFileChooser가 팝업되게하고 싶습니다. 나는 그것이 전체 파일 경로를 반환하려면,이버튼을 클릭 한 JFileChooser 클릭
JButton browse= new JButton("Browse");
add(browse);
browse.addActionListener(new ClassBrowse());
public class ClassBrowse implements ActionListener {
public void actionPerformed(ActionEvent e) {
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
// return the file path
} catch (Exception ex) {
System.out.println("problem accessing file"+file.getAbsolutePath());
}
}
else {
System.out.println("File access cancelled by user.");
}
}
}
BHE 위 또한 오류를 The method showOpenDialog(Component) in the type JFileChooser is not applicable for the arguments (ClassName.ClassBrowse)
을 제공 노력했다. 어떻게해야합니까?
JFrame을 어딘가에 설치했다고 가정하고''int returnVal = fileChooser.showOpenDialog (this);''를''int returnVal = fileChooser.showOpenDialog (frame);''로 대체하십시오. 당신의 코드. – santafebound