JFileChooser.showSaveDialog: All files greyed out

前端 未结 3 1461
星月不相逢
星月不相逢 2021-01-18 12:25

I\'m trying to use the JFileChooser to get files for loading and saving. The dialog that comes up with openFileDialog() works fine, but when I use

3条回答
  •  再見小時候
    2021-01-18 12:46

    Mmm... I think, that show dialogs the way you do is not the best way

    chooser.showOpenDialog(null);
            chooser.showSaveDialog(null);
    

    I think that could be generating a conflict. Why don't you try to use a JFrame to help you? Try with this piece of code, just to know if the problem is the saveDialog. Myabe then you can adapt it to your programming requirements.

    JFrame parentFrame = new JFrame();
    
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Specify a file to save");    
    
    int userSelection = fileChooser.showSaveDialog(parentFrame);
    
    if (userSelection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = fileChooser.getSelectedFile();
        System.out.println("Save as file: " + fileToSave.getAbsolutePath());
    }
    

    As a matter of fact, you could try using the setLookAndFeel, I remember I had this issue working with my Macbook Pro.

提交回复
热议问题