أريد ان استدع ملف عن طريق JFileChooser و أريد أن يظهر لي مساره على textField مثل c:\\java\test.txt
هدا هو كود
import java.awt.BorderLayout;
public class DDDDD extends JFrame {
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DDDDD frame = new DDDDD();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public DDDDD() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 342, 188);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(10, 23, 261, 20);
contentPane.add(textField);
textField.setColumns(10);
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser choice = new JFileChooser();
choice.setFileSelectionMode(JFileChooser.FILES_ONLY);
int res =choice.showOpenDialog(null);
if(res==JFileChooser.CANCEL_OPTION) return;
File FilemyFile = choice.getSelectedFile();
}
});
btnNewButton.setBounds(281, 22, 43, 23);
contentPane.add(btnNewButton);
}
}