[英]How change the image of open Dialog box and how to customize Dialog box in swing?
打开显示对话框的文件时,需要更改Java映像并添加自己的映像。 如何自定义对话框?
例如,我需要将“编码”添加到对话框中,以及如何将不同类型的文件添加到“文件类型”下拉框中。 例如,我将text
, java
, html
添加到Files of type
框。
这是我的代码,
FileDialog fd = new FileDialog(OpenExample.this, "Select File", FileDialog.LOAD);
fd.setVisible(true);
要为文件选择器或对话框提供图标,请为父框架设置一个图标。
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);
}
}
..如何将不同类型的文件添加到文件类型下拉框? 例如:将
text
,java
,html
添加到Files of type
框。
请参阅如何使用文件选择器:FileChooserDemo2 ,它为Just Images
提供文件过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.