Tree in scala swing

倾然丶 夕夏残阳落幕 提交于 2019-12-10 04:31:40

问题


I want to use a tree in my Scala swing application, but the component isn't available in the API.

Does a wrapper of JTree exists ?

If not, do you have any advice for making it ?

Thanks


回答1:


Even though you can use directly the Java JTree in your scala program, as illustrated by this thread, there is a debate about including a Scala wrapper of a JTree.

The following common usages are tedious, verbose, non-type safe, and/or require unsafe null usage:

  • Creating a custom tree model, backed by your own user objects -- the Scala Swing way would be to have a standard typesafe Map behind it
  • Events - there are heaps of events created by trees -- TreeWillExpandListeners, TreeSelection, etc -- Using the Reactor/Publisher PartialFunction model would make this code far more readable and concise.
  • Editable components -- This is done with implicit values elsewhere in scala.swing, and should be here too.
  • Custom renderers -- Can't remember how Scala deals with these, but this is always fiddly in Java Swing too.

Bottom line is, JTrees are a massive pain to use in Java, for no particularly good reason. A Scala wrapper would be a massive boon for Scala Swing users.

A design is in progress, and a JTree wrapper proposal is available in this GitHub repo, made by kenbot (Ken Scambler).



来源:https://stackoverflow.com/questions/4049628/tree-in-scala-swing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!