How to change java default icon in JFileChooser

I want to change the inline java icon from JFileChooser. JFramethe class has a method setIconImage()for setting the icon. But I could not find anything like that for JFileChooser. Without changing this cup of coffee, you can easily understand that my software was created using java. Can someone help me avoid this?

+3
source share
4 answers

The IIRC icon for JFileChooser is taken from the transmitted jFrame. By changing the icon for the JFrame, you should also get a reflected icon change in the JFileChooser.

code:

JFileChooser choice = new JFileChooser()
choice.showOpenDialog(parent);

The icon that is used is the icon from the parent.

+10
source

:

JFileChooser fc = new JFileChooser(new File("C:/")){
    @Override
    protected JDialog createDialog( Component parent ) throws HeadlessException {
        JDialog dialog = super.createDialog( parent );
        BufferedImage image = new BufferedImage( 16, 16, BufferedImage.TYPE_3BYTE_BGR );
        dialog.setIconImage( image );
        return dialog;
    }
};
fc.showOpenDialog(frame);
+6
javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(new java.io.File("C:/Users/Documents")) {
            @Override
            protected javax.swing.JDialog createDialog(java.awt.Component parent) throws java.awt.HeadlessException {
                javax.swing.JDialog dialog = super.createDialog(parent);

                dialog.setIconImage(new
                        javax.swing.ImageIcon("C:/Img.png").getImage());

                return dialog;

            }
        };
+1
source

Source: https://habr.com/ru/post/1723727/


All Articles