java 问题:保存对话框的默认文件类型

来源:百度知道 编辑:UC知道 时间:2024/05/17 22:50:20
怎样设置保存对话框的默认文件类型
怎样设置打开对话框的默认文件类型和过滤器?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.File;

public class L extends JFrame
{
/**
* @param args
*/
public static void main(String[] args)throws Exception
{
new ConfigFrame("保存文件");
}
}
class ConfigFrame extends JFrame
{
private static final long serialVersionUID = 1L;

public ConfigFrame(String title)
{
//设置窗口属性
final int width = 300;
final int height = 200;
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
final int left = (screen.width - width)/2;
final int top = (screen.height - height)/2;
this.setLocation(left, top);
this.setSize(width,height);
this.setTitle(title);

//添加组件
JPanel panel = new JPanel();
this.add(panel);
JButton b = new JButton("打开");