开发者

How to change default java icon in JFileChooser

I want to change the inbuilt java icon fro开发者_如何学Cm 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?


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.


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


See:

  • How to change JFileChooser's title bar icon.


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;

            }
        };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜