1

This is the code that I use at the moment but it really spoils the whole beautifullness of the program. I would like this function to apply only to JFilechooser without changing of all other components like JButton etc.

I just find the native Java filechooser to be very ugly and inconvinient compared to native Windows style.

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

After I received an answer and looked into the link it helped me to solve my problem. I will post the code that I now use in order to help anyone that will ever need this.

Solution found:

import javax.swing.JFileChooser;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class window {
    public static void main(String[] args) {    
        //Open file chooser
        JFileChooser chooser = windowsJFileChooser(new JFileChooser());//Create file chooser
        chooser.showSaveDialog(null);
    }

    /**
     * This method returns JFileChooser with Windows look instead of native java
     * @param chooser
     */
    public static JFileChooser windowsJFileChooser(JFileChooser chooser){
        LookAndFeel previousLF = UIManager.getLookAndFeel();
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            chooser = new JFileChooser();
            UIManager.setLookAndFeel(previousLF);
        } catch (IllegalAccessException | UnsupportedLookAndFeelException | InstantiationException | ClassNotFoundException e) {}
        return chooser;
    }
}
Corey
  • 94
  • 10
  • Does this answer your question? [How to change the look and feel of a single part of a java program](https://stackoverflow.com/questions/11872492/how-to-change-the-look-and-feel-of-a-single-part-of-a-java-program) – Hakan Dilek Jun 11 '20 at 19:21
  • You should also read [this question](https://stackoverflow.com/questions/18424854/changing-look-and-feel-of-specific-window) for more background. – MarsAtomic Jun 11 '20 at 19:28
  • I would like to thank both of you MarsAtomic and Hakan Dilek. Indeed the link helped me. After I adapted that code I also added the solution to this question here just to make it easier for anyone that will ever look for this as well. Thank you for your very quick reply and for everything. – Corey Jun 11 '20 at 19:36

0 Answers0