我只能猜测,但我认为你需要一个JFrame其中将包含您的JFileChooser,我犯了一个小例子,没有任何功能,只是为了展示,你怎么可以或许达到自己的目标。
请了解你的下一个问题(S)在这里SO,上传你尝试和POST错误/异常你,否则就很难帮助或解决您的问题!
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.professional_webworkx.tutorial.jtable.view;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
/**
*
* @author ottp
*/
public class MainFrame extends JFrame {
private JFileChooser chooser;
public MainFrame() {
initGUI();
}
private void initGUI() {
chooser = new JFileChooser();
chooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(chooser.getSelectedFile().getName());
}
});
this.setTitle("FileChoosing and copy one file to another");
this.setSize(1024, 768);
this.getContentPane().add(chooser, BorderLayout.NORTH);
this.setVisible(true);
}
}
的班,开始你的App
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.professional_webworkx.tutorial.jtable;
import de.professional_webworkx.tutorial.jtable.view.MainFrame;
import javax.swing.JFileChooser;
/**
*
* @author ottp
*/
public class JTableDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new MainFrame();
}
}
希望这有助于 帕特里克
你得到什么错误? – Salah