Thusitha
Thusitha

Reputation: 3511

How to change default java icon in JFileChooser

I want to change the inbuilt java icon from JFileChooser. JFrame class has a setIconImage() method for set icon.But I couldn't find anything like that for JFileChooser. Without changing that coffee cup anyone can easily recognize that my software is made with java. Can anyone can help me to avoid this?

Upvotes: 3

Views: 14125

Answers (4)

Luis
Luis

Reputation: 21

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;

            }
        };

Upvotes: 1

oliholz
oliholz

Reputation: 7507

This could help:

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);

Upvotes: 7

Anya Shenanigans
Anya Shenanigans

Reputation: 94614

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

the code:

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

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

Upvotes: 13

mre
mre

Reputation: 44240

See:

Upvotes: 3

Related Questions