[英]How to display JTree file in JTextArea
In my program i have a JTree
which is being populated by a number of folders and files.在我的程序中,我有一个
JTree
,它由许多文件夹和文件填充。 When you select a file in the JTree
I want that file to display in the JTextArea
.当您在
JTree
选择一个文件时,我希望该文件显示在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
?我不,您可以使用
getLastSelectedPathComponent()
从JTree
获取最后一个选定的项目,该项目可用于从树中获取所选文件,但这是树的一个节点......有没有办法从中获取文本这个节点喜欢使用FileReader
和BufferReader
吗?
I would put File
objects in the tree and use a cell renderer to show (render) them as required.我会将
File
对象放在树中并使用单元渲染器根据需要显示(渲染)它们。
See File Browser GUI for an example.有关示例,请参阅文件浏览器 GUI 。 The example also demonstrates how to retrieve details of the selected file or directory.
该示例还演示了如何检索所选文件或目录的详细信息。 It uses the
Desktop
class to display(/print/edit) files.它使用
Desktop
类来显示(/打印/编辑)文件。
Not directly.不直接。 What you will need to do:
你需要做什么:
DefaultMutableTreeNode
for this.DefaultMutableTreeNode
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.