JFileChooser change default directory in Windows

前端 未结 7 1009
粉色の甜心
粉色の甜心 2021-02-12 16:27

I want to change the default directory of my JFileChooser to \"My Music\" on Windows. This directory is C:\\Users\\Fre\\Music on my account because my username is <

相关标签:
7条回答
  • 2021-02-12 16:54

    You can Change the default directory of my JFileChooser to "Directory you want" on Windows

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File("put here your directory"));
    int result = fileChooser.showOpenDialog(getParent());
    if (result == JFileChooser.APPROVE_OPTION) 
    {
        File selectedFile = fileChooser.getSelectedFile();
        jTextField.setText(selectedFile.getAbsolutePath());
    }
    
    0 讨论(0)
提交回复
热议问题