- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Is there a Scala swing JTree ?
Fri, 2010-02-12, 16:27
Isn't there a way of creating and using a JTree via scala.swing? The docs don't seem to list a JTree equivalent.
Thanks for any help.
- Sanjay
Thanks for any help.
- Sanjay
Sat, 2010-02-13, 03:27
#2
Re: Is there a Scala swing JTree ?
Certainly one can get by without a wrapped version, but I disagree that it's
not worth the effort to wrap it, it's a conspicuous absence in the Scala
Swing API.
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.
-Ken
Martin S. Weber-2 wrote:
>
> On 02/12/10 10:27, Sanjay Dasgupta wrote:
>> Isn't there a way of creating and using a JTree via scala.swing? The docs
>> don't seem to list a JTree equivalent.
>>
>
> I use the JTree directly, wrapped in a Component, e.g.
> new ScrollPane {
> contents = new Component {
> override lazy val peer = new JTree(new DefaultTreeModel(root)) {
> addTreeSelectionListener(new TreeSelectionListener {
> def valueChanged(e: TreeSelectionEvent) {
> //...
> }
> })
> addMouseListener(new java.awt.event.MouseAdapter {
> override def mousePressed(e: JMouseEvent) {
> //...
> }
> override def mouseReleased(e: JMouseEvent) {
> //...
> }
> })
> }
> }
> // somewhere also revalidate/repaint
>
> i.e. it's easy enough wrapped to survive not having it wrapped already
>
> Hth,
>
> -Martin
>
>
Sat, 2010-02-13, 10:17
#3
Re: Is there a Scala swing JTree ?
Thanks, Ken.
That's a fair analysis of what needs to be done. Moreover, one could
experiment with swinglabs JXTreeTable for an ultimate list/table/tree
view. I don't know whether that's the silver bullet though, as I don't
have enough experience with it.
Would you like to work on a wrapper?
Ingo
On 2/13/10 3:22 AM, Ken Scambler wrote:
>
> Certainly one can get by without a wrapped version, but I disagree that it's
> not worth the effort to wrap it, it's a conspicuous absence in the Scala
> Swing API.
>
> 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.
> -Ken
>
>
> Martin S. Weber-2 wrote:
>>
>> On 02/12/10 10:27, Sanjay Dasgupta wrote:
>>> Isn't there a way of creating and using a JTree via scala.swing? The docs
>>> don't seem to list a JTree equivalent.
>>>
>>
>> I use the JTree directly, wrapped in a Component, e.g.
>> new ScrollPane {
>> contents = new Component {
>> override lazy val peer = new JTree(new DefaultTreeModel(root)) {
>> addTreeSelectionListener(new TreeSelectionListener {
>> def valueChanged(e: TreeSelectionEvent) {
>> //...
>> }
>> })
>> addMouseListener(new java.awt.event.MouseAdapter {
>> override def mousePressed(e: JMouseEvent) {
>> //...
>> }
>> override def mouseReleased(e: JMouseEvent) {
>> //...
>> }
>> })
>> }
>> }
>> // somewhere also revalidate/repaint
>>
>> i.e. it's easy enough wrapped to survive not having it wrapped already
>>
>> Hth,
>>
>> -Martin
>>
>>
>
Sat, 2010-02-13, 15:37
#4
Re: Is there a Scala swing JTree ?
Hi Ingo,
Sure, I'll give it a go, thanks. Between the scala.swing source and your
SID there should be enough of a basis for a sound design. I haven't used
the JXTreeTable either -- it sounds like it might be worth a look.
Ken
Ingo Maier-3 wrote:
>
> Thanks, Ken.
>
> That's a fair analysis of what needs to be done. Moreover, one could
> experiment with swinglabs JXTreeTable for an ultimate list/table/tree
> view. I don't know whether that's the silver bullet though, as I don't
> have enough experience with it.
>
> Would you like to work on a wrapper?
>
> Ingo
>
> On 2/13/10 3:22 AM, Ken Scambler wrote:
>>
>> Certainly one can get by without a wrapped version, but I disagree that
>> it's
>> not worth the effort to wrap it, it's a conspicuous absence in the Scala
>> Swing API.
>>
>> 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.
>> -Ken
>>
>>
>> Martin S. Weber-2 wrote:
>>>
>>> On 02/12/10 10:27, Sanjay Dasgupta wrote:
>>>> Isn't there a way of creating and using a JTree via scala.swing? The
>>>> docs
>>>> don't seem to list a JTree equivalent.
>>>>
>>>
>>> I use the JTree directly, wrapped in a Component, e.g.
>>> new ScrollPane {
>>> contents = new Component {
>>> override lazy val peer = new JTree(new DefaultTreeModel(root)) {
>>> addTreeSelectionListener(new TreeSelectionListener {
>>> def valueChanged(e: TreeSelectionEvent) {
>>> //...
>>> }
>>> })
>>> addMouseListener(new java.awt.event.MouseAdapter {
>>> override def mousePressed(e: JMouseEvent) {
>>> //...
>>> }
>>> override def mouseReleased(e: JMouseEvent) {
>>> //...
>>> }
>>> })
>>> }
>>> }
>>> // somewhere also revalidate/repaint
>>>
>>> i.e. it's easy enough wrapped to survive not having it wrapped already
>>>
>>> Hth,
>>>
>>> -Martin
>>>
>>>
>>
>
>
>
On 02/12/10 10:27, Sanjay Dasgupta wrote:
> Isn't there a way of creating and using a JTree via scala.swing? The docs don't seem to list a JTree equivalent.
>
I use the JTree directly, wrapped in a Component, e.g.
new ScrollPane {
contents = new Component {
override lazy val peer = new JTree(new DefaultTreeModel(root)) {
addTreeSelectionListener(new TreeSelectionListener {
def valueChanged(e: TreeSelectionEvent) {
//...
}
})
addMouseListener(new java.awt.event.MouseAdapter {
override def mousePressed(e: JMouseEvent) {
//...
}
override def mouseReleased(e: JMouseEvent) {
//...
}
})
}
}
// somewhere also revalidate/repaint
i.e. it's easy enough wrapped to survive not having it wrapped already
Hth,
-Martin