Java – how to use Jfilechooser to get directory paths?

I have a small java GUI application with a text field on it When the user clicks the text field, an event is triggered and Jfilechooser. Exe is started It is limited to directories

What I want to do is get the full path of the selected directory and put it in the text field

I don't know what to do. I searched a lot of Java tutorials and documents, and I couldn't find the answer Can someone help me?

To clarify, I want to take a complete path as a string and put it in the text field, overwriting anything before

Solution

Try like

myTextField.setText(myFileChooser.getSelectedFile().getAbsolutePath());

What are you doing? Retrieving the file object from the file chooser, grabbing its path and throwing it into the text field

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>