How to change default java icon in JFileChooser

天涯浪子 提交于 2019-12-10 20:48:08

问题


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?


回答1:


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.




回答2:


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



回答3:


See:

  • How to change JFileChooser's title bar icon.



回答4:


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;

            }
        };


来源:https://stackoverflow.com/questions/6994772/how-to-change-default-java-icon-in-jfilechooser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!