简体   繁体   中英

How change the image of open Dialog box and how to customize Dialog box in swing?

When I open file that show the dialog box, I need to change Java image and add my own image. How to customize dialog box?

For example, I need to add the Encoding to the dialog box and how to add different type of files to Files of type dropdown box. For Example, i add text , java , html to Files of type box.

Here is my code,

FileDialog fd = new FileDialog(OpenExample.this, "Select File", FileDialog.LOAD);
fd.setVisible(true);

To provide an icon for a file chooser or dialog, set an icon for the parent frame.

在此处输入图片说明

import java.awt.image.BufferedImage;
import javax.swing.*;

public class FileChooserIcon {

    public static void main(String[] args) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                try {
                    // see nice icons in chooser!
                    UIManager.setLookAndFeel(
                            UIManager.getSystemLookAndFeelClassName());
                } catch (Exception useDefault) {}
                JLabel ui = new JLabel("Big Space");
                ui.setBorder(new javax.swing.EmptyBorder(40, 200, 40, 200));

                JFrame f = new JFrame("Show file chooser icon");
                f.setIconImage(new BufferedImage(
                        20, 20, BufferedImage.TYPE_INT_RGB));
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setContentPane(ui);
                f.pack();
                f.setLocationByPlatform(true);
                f.setVisible(true);

                JFileChooser jfc = new JFileChooser();
                jfc.showOpenDialog(f); // use frame icon!
            }
        };
        SwingUtilities.invokeLater(r);
    }
}

.. how to add different type of files to Files of type dropdown box? For example: add text , java , html to Files of type box.

See How to Use File Choosers: FileChooserDemo2 which offers a file filter for Just Images ..

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM