前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >javafx框架tornadofx入门实战23_treeview_advanced

javafx框架tornadofx入门实战23_treeview_advanced

原创
作者头像
用户6167008
修改2020-03-31 14:41:31
2.2K1
修改2020-03-31 14:41:31
举报

treeview构建2棵有关联的文件(夹)树,通过tornadofx提供的populate,仅用3行代码实现一棵树。并可在右侧窗口查看文本文件的内容和图片

代码语言:txt
复制
import com.dlsc.gemsfx.PDFView
import javafx.scene.control.*
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.scene.layout.Priority
import javafx.scene.layout.StackPane
import javafx.scene.web.WebView
import org.apache.tika.Tika
import tornadofx.*
import java.io.File


class FileBrowserView : View("tornadofx入门23_treeview_advanced") {
    val leftFile = objectProperty<File>()
    val rightFile = objectProperty<File>()
    val fileTyle = stringProperty()
    lateinit var webEngine: WebView
    val pdfview = PDFView().apply { vgrow = Priority.ALWAYS }

    val img = objectProperty<Image>()
    val txt = stringProperty()
    lateinit var contentView: StackPane
    //    lateinit var txtV: TextArea
    lateinit var imgV: ImageView
    val rightRoot = objectProperty<TreeItem<File>>(TreeItem(File(".")))
    lateinit var rightTree: TreeView<File>

    val tika = Tika()

    override val root = borderpane {
        top {
        }
        left = hbox(4) {
            treeview<File> {
                root = TreeItem(File("."))
                populate {
                    it.value.listFiles()?.asList()?.filter {
                        it.isDirectory
                    }
                }
                bindSelected(leftFile)
                leftFile.onChange {
                    rightRoot.value = TreeItem(leftFile.value)
                    rightTree.populate {
                        it.value.listFiles()?.asList()
                    }
                }
                cellFormat {
                    text = it.name
                    graphic = nodeGraphic(it)
                }
                vgrow = Priority.ALWAYS
            }
            treeview<File> {
                rightTree = this
//                root = TreeItem(File("."))
                rootProperty().bind(rightRoot)
                isShowRoot = false
                populate {
                    it.value.listFiles()?.asList()
                }
                bindSelected(rightFile)
                rightFile.onChange {
                    val f = rightFile.value
                    displayFile(f)
                }
                cellFormat {
                    text = it.name
                    graphic =nodeGraphic(it)
                }
                vgrow = Priority.ALWAYS
            }
        }
        center = vbox {
            stackpane {
                imageview(img) {
                    imgV = this
                    fitWidth = 400.0
                    fitHeight = 400.0
                }
//                    textarea(txt) {
//                        txtV = this
//                        vgrow = Priority.ALWAYS
//                    }
                webview {//用于显示文本内容
                    webEngine = this
                    vgrow = Priority.ALWAYS
                }
                stackpane {
                    label()
                    contentView = this
                    vgrow = Priority.ALWAYS
                }
                vgrow = Priority.ALWAYS

            }
            label(stringBinding(fileTyle) { "文件类型:${this.value}" })
        }

        setPrefSize(1024.0, 768.0)
    }
image.png
image.png
image.png
image.png

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • treeview构建2棵有关联的文件(夹)树,通过tornadofx提供的populate,仅用3行代码实现一棵树。并可在右侧窗口查看文本文件的内容和图片
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档