我只能猜測,但我認爲你需要一個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