⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmguifilechoose.java

📁 梦界家园程序开发基底框架
💻 JAVA
字号:
package jm.framework.gui.container;

import java.awt.event.ActionEvent;

import javax.swing.JComponent;
import javax.swing.JFileChooser;

import jm.framework.gui.module.JMPanel;
import jm.framework.gui.module.JMTextField;
import jm.util.JMVector;

/**
 * <p>Title: JM 整合Swing控件,使用配置信息</p>
 *
 * <p>Copyright: Copyright (c) 2004-2006</p>
 *
 * <p>Company: 1SHome</p>
 *
 * <p>@author Spook</p>
 *
 * @since 1.3
 * @see JDK 1.5.0.6
 */
public class JMGUIFileChoose extends JMGUIAbstractContralPanel implements JMGUIActionListener {

    /**
     *
     */
    private static final long serialVersionUID = 6412706488560784659L;
    public JMGUIFileChoose () {
        super(new JMPanel());
    }

    /**
     * 初始化
     * @throws Exception
     * @todo Implement this jm.framework.gui.module.JMContralComponent method
     */
    public void load () throws Exception {
        ValueComponent = new JMVector<JComponent>(5);

        JMTextField _component_ = null;

        _component_ = new JMTextField();
        _component_.setText(Value.get(0));
        if (Request) {
            _component_.setBackground(getRequestColor());
        }
        RootPanel.add(_component_);
        ValueComponent.add(_component_);
        addCommandActionListener(this);
        super.load();
    }

    /**
     * 获得显示控件的内容
     *
     * @return JMVector
     * @todo Implement this jm.framework.gui.module.JMContralComponent method
     */
    public JMVector<String> getValue () {
        Value = new JMVector<String>();
        for (JComponent _valueComponent_ : ValueComponent) {
            Value.add(((JMTextField) _valueComponent_).getText());
        }

        return Value;
    }

    ////////////////////////////////////////////////////////////////////////////
    /**
     * 文件类型
     */
    JMVector<String> Extension = null;
    /**
     * 设置文件类型
     * @param extensions String[]
     */
    public void setExtension (String ...extensions) {
        for (String extension : extensions) {
            Extension.add(extension);
        }
    }

    /**
     * 获得文件类型
     */
    public JMVector<String> getExtension () {
        return Extension;
    }

    /**
     * 文件过滤提示信息
     */
    String Description = "All files";
    /**
     * 设置文件过滤提示信息
     * @param description String
     */
    public void setDescription (String description) {
        Description = description;
    }
    /**
     * 获得文件过滤提示信息
     * @return String
     */
    public String getDescription () {
        return Description;
    }

    ////////////////////////////////////////////////////////////////////////////
    JFileChooser Chooser = null;
    /**
     * 初始化选择文件窗口
     */
    private void loadChooser(){
        Chooser = new JFileChooser();
        JMGUIFileFilter filter = new JMGUIFileFilter();
        if (Extension != null&&Extension.size()>1) {
            for (String extension : Extension) {
                filter.addExtension(extension);
            }
            Chooser.setFileFilter(filter);
        }
        filter.setDescription(Description);

    }
    /**
     * 按钮点击
     * @param e ActionEvent
     */
    public void actionPerformed (ActionEvent e) {
        if (Chooser == null) {
            loadChooser();
        }
        int returnVal = Chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            ((JMTextField) ValueComponent.get(0)).setText(Chooser.getSelectedFile().getPath());
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -