Tree in scala swing
Asked Answered
S

1

8

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

Soniasonic answered 29/10, 2010 at 6:49 Comment(0)
L
9

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).

Lough answered 29/10, 2010 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.