当前位置: 代码迷 >> J2SE >> JavaSE如何实现浏览按钮
  详细解决方案

JavaSE如何实现浏览按钮

热度:1689   发布时间:2013-02-25 00:00:00.0
JavaSE怎么实现浏览按钮,
JavaSE怎么实现浏览按钮,点击出现windows资源管理器选择文件。
求大神给个思路,怎么实现。

------解决方案--------------------------------------------------------
有个组建
------解决方案--------------------------------------------------------
用FileDialog可以做,JFileChooser也可以做。
参见:
http://www.iteye.com/topic/1116890
------解决方案--------------------------------------------------------
Java code
JButton jbfile=new JButton();JTextField jtfile=new JTextField("",10);jbfile.addActionListener(new ImportFrame_jbfile_actionAdapter(this));      public void jbfile_actionPerformed(ActionEvent e) {     //建立文件选择框对象    JFileChooser fc=new JFileChooser();    //设定文件选择框标题    fc.setDialogTitle("Open class File");    //显示文件选择框,在选择后将结果储存到returnVal变量中    int returnVal = fc.showOpenDialog(this.getComponent(0));    //如果用户选择了文件,并点击了"Opne/打开"按钮,显示用户选择的文件全名路径,    //如果用户点击"Close/关闭"按钮,以及其它方式退出文件选择框,则什么也不做。    if (returnVal == JFileChooser.APPROVE_OPTION){    File file = fc.getSelectedFile();    jtfile.setText(file.getPath());     }         }class ImportFrame_jbfile_actionAdapter implements ActionListener {    private ImportFrame adaptee;    ImportFrame_jbfile_actionAdapter(ImportFrame            adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.jbfile_actionPerformed(e);    }}