teamyates
teamyates

Reputation: 434

Having the windows UI display when using JFileChooser

Currently using JFileChooser to save a file to the users system. Issue is that the user interface it uses to select the file destination is the ugly Swing UI and not the Windows file explorer UI. Is there an attribute that I can easily change for the JFileChooser.

Below is my code:

  JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Specify a file to save");

    int userSelection = fileChooser.showSaveDialog(this);

    if (userSelection == JFileChooser.APPROVE_OPTION) {
        fileToSave = fileChooser.getSelectedFile();
        String filePath = fileToSave.getPath();
        if(!filePath.toLowerCase().endsWith(".csv"))
        {
            fileToSave = new File(filePath + ".csv");
        }
    }

I have also defined fileToSave earlier and the code all works, this is purely a cosmetic issue.

Upvotes: 0

Views: 1225

Answers (1)

Doga Oruc
Doga Oruc

Reputation: 826

As Andrew Thompson mentioned, UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); is the method you are looking for.

Try this:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //set Look and Feel to Windows
JFileChooser fileChooser = new JFileChooser(); //Create a new GUI that will use the current(windows) Look and Feel
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); //revert the Look and Feel back to the ugly Swing

// rest of the code...

Upvotes: 3

Related Questions