[英]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. 打开显示对话框的文件时,需要更改Java映像并添加自己的映像。 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. 例如,我将text
, java
, html
添加到Files of type
框。
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
toFiles of type
box. 例如:将text
,java
,html
添加到Files of type
框。
See How to Use File Choosers: FileChooserDemo2 which offers a file filter for Just Images
.. 请参阅如何使用文件选择器:FileChooserDemo2 ,它为Just Images
提供文件过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.