import java.awt.BorderLayout;
import java.awt.event.ActionEvent를 실행합니다.
import java.awt.event.ActionListener 입니다.
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
가져 오기 javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class SaveDialog {
public static void main(String[] args) {
final JFrame window = new JFrame();
window.setSize(200,200);
window.setLocationRelativeTo(null);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
JMenuBar jmb = 새로운 JMenuBar();
JMenu jm = 새로운 JMenu("Ficher");
JMenuItem 저장 = new JMenuItem("저장");
jm.add(저장);
jmb.add(jm);
window.add(jmb,BorderLayout.NORTH);
JFileChooser fc = 새로운 JFileChooser();
Save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO 자동 생성 메소드 stub
int val_retour = fc.showSaveDialog(window);
if (val_retour == JFileChooser.APPROVE_OPTION) {
파일 파일 = fc.getSelectedFile();
//파일의 절대 경로 표시
System.out.println("절대 경로: "+file.getAbsolutePath()+"\n");
} else {
System.out.println("등록이 취소되었습니다.\n");
}
}
});
}
}
절대 경로: C:\Users\VAIO\Documents\CC++\test.txt변경할 수 있습니다. 파일 선택 모드. 예를 들어, 다음 코드 행을 사용하면 JFileChooser의 폴더만 select 할 수 있습니다:
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);또 다른 선택 모드는 FILES_AND_DIRECTORIES스팬>. 기본 설정은 FILES_ONLY.
Please disable your ad blocker and refresh the window to use this website.