JFileChooser.showSaveDialog: All files greyed out

若如初见. 提交于 2019-12-01 17:37:11
trashgod

I'm looking for the .txt files to be displayed in the "normal" color while in the save dialog.

That's controlled by the FileChooserUI delegate specific to a particular Look & Feel, e.g. AquaFileChooserUI on Mac OS X. You can use a different L&F, (laboriously) write your own FileChooserUI, or develop a custom File Browser GUI.

Matthew

What I ended up doing was to use:

JFileChooser chooser = new JFileChooser(...);
chooser.showDialog(myFrame, "Save");

My save dialog looks like a save dialog, and the FileFilter greys out only files that fail its test.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!