In my program i have a JTree
which is being populated by a number of folders and files. When you select a file in the JTree
I want that file to display in the JTextArea
.
I no you can use getLastSelectedPathComponent()
to get the last selected item from the JTree
which can be used to get the chosen file from the tree but this is then a node of the tree... is there a way to get the text from this node like using a FileReader
and a BufferReader
?
I would put File
objects in the tree and use a cell renderer to show (render) them as required.
See File Browser GUI for an example. The example also demonstrates how to retrieve details of the selected file or directory. It uses the Desktop
class to display(/print/edit) files.
Not directly. What you will need to do:
DefaultMutableTreeNode
for this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.