Skip to main content

RE: Setting editor/renderer for JTreeTable

15 replies [Last post]
Anonymous

The JDNC demos have a more graphical approach to the tree in the treetable. There are no tree lines, and no visible structure. As an example, can you point me to where this code was implemented? It
wasn't readily apparent when I was looking though the source.

Thanks.
-jonathan

-----Original Message-----
From: jdnc-interest@javadesktop.org [mailto:jdnc-interest@javadesktop.org]
Sent: Wednesday, July 28, 2004 4:34 PM
To: jdnc@jdnc.dev.java.net
Subject: Re: Setting editor/renderer for JTreeTable

> I'm trying to switch my old JTreeTable code out for
> the new JDNC stuff. Im having trouble setting a new
> editor/renderer for the tree.

Do you have a custom tree cell renderer and editor with specialized needs? If so, we'd like to know.

The new treetable design treats the tree strictly as an implementation detail and does not leak a reference to that through the public api. This is to ensure that the internal state of the tree stays
in sync with the state of the treetable.

All of the work necessary to set up the renderer and editor for the hierarchical column is done internally by JTreeTable. Please see JTreeTable.setTreeTableModel for details on how this is done. The
idea is that users should not have to deal with these.

>
> Basically, I dont want the tree to look like a file
> explorerer -- I actually want it to look more like
> the demo for the JDNC XML stuff. (speaking of which,
> I dug through the src and didnt immediately see that
> code either).
>
> Any tips?

JTreeTable has dedicated methods for these. Please see setOpenIcon, setClosedIcon, setLeafIcon, setExpandedIcon, and setCollapsedIcon.

Hope this helps.

Ramesh
---
[Message sent by forum member 'rameshgupta' (Ramesh Gupta)]

http://www.javadesktop.org/forums/thread.jspa?messageID=19755&#19755

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

==============================================================================

If you are not an intended recipient of this e-mail, please notify
the sender, delete it and do not read, act upon, print, disclose,
copy, retain or redistribute it.

Click here for important additional terms relating to this e-mail.

==============================================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Simon, Jonathan (GMIT Repo Systems)

> Glad to hear that you got your existing code to work with JDNC!

I did get it to work -- but it required me to extend a UI class, write my own treeCellRenderer, and modify the source of JTreeTable itself... not exactly an easy experience.

But I *am* using it :)

-jonathan

==============================================================================

If you are not an intended recipient of this e-mail, please notify
the sender, delete it and do not read, act upon, print, disclose,
copy, retain or redistribute it.

Click here for important additional terms relating to this e-mail.

==============================================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

rameshgupta
Offline
Joined: 2004-06-04

> > Glad to hear that you got your existing code to
> > work with JDNC!
>
> I did get it to work -- but it required me to extend
> a UI class, write my own treeCellRenderer, and modify
> the source of JTreeTable itself... not exactly an
> easy experience.
>
> But I *am* using it :)
>
> -jonathan

Why UI class? Also, we'd like you to share your experience with us in greater detail, if possible, so that we can avoid baking in some of our mistakes into the final api.

Ramesh

nsushkin
Offline
Joined: 2004-04-22

It would be nice to be able to override the tree cell renderer without modifying your own copy of JXTreeTable.

Currently, the ClippedTreeCellRenderer is hardwired into JXTreeTable, but it extends DefaultTreeCellRenderer that uses a JLabel to display Object.toString() of the underlying row object.

There is no way to override which text is being displayed in the tree.

Suppose you have thousands of objects in your application that you want to display in a JXTreeTable. Following JTree design, you roll your own implementation of TreeTableModel and renderers that provide JXTreeTable with enough information to be able to build a tree and components to display each cell. Why can't the same design pattern apply to JXTreeTable?

rameshgupta
Offline
Joined: 2004-06-04

> It would be nice to be able to override the tree cell
> renderer without modifying your own copy of
> JXTreeTable.
>
> Currently, the ClippedTreeCellRenderer is hardwired
> into JXTreeTable, but it extends
> DefaultTreeCellRenderer that uses a JLabel to display
> Object.toString() of the underlying row object.
>
> There is no way to override which text is being
> displayed in the tree.
>
> Suppose you have thousands of objects in your
> application that you want to display in a
> JXTreeTable. Following JTree design, you roll your
> own implementation of TreeTableModel and renderers
> that provide JXTreeTable with enough information to
> be able to build a tree and components to display
> each cell. Why can't the same design pattern apply to
> JXTreeTable?

You are right. This is a big problem in the current design. I am looking into ways to cleanly support custom editors and renderers for the hierarchical column without exposing internal details. Will post as soon as I have something ready.

Ramesh

rbair
Offline
Joined: 2003-07-08

Hey Ramesh,

> You are right. This is a big problem in the current
> design. I am looking into ways to cleanly support
> custom editors and renderers for the hierarchical
> column without exposing internal details. Will post
> as soon as I have something ready.
>
> Ramesh

One possible approach would be to create a TreeTableCellRenderer, similar to the TreeCellRenderer but with different params. It would help enforce the idea that a TreeTable is a new kind of beast, sort of like a Tree and sort of like a table. I don't like the idea of exposing the tree itself, or even the table, if we could help it. That allows us to change the implementation.

Not being an expert on our JXTreeTable -- maybe that's what you guys have already done :)

Richard

arooaroo
Offline
Joined: 2005-04-06

Ah, so is this why I can't get JXTreeTable to render JComponents within a table?

Why is it also that it won't display Booleans as checkboxes? The Javadocs show that JXTable has a BooleanRenderer, so I'd assume this would work out of the box?

Regards

Kleopatra

Hi Andy,

>
> Why is it also that it won't display Booleans as checkboxes?
> The Javadocs show that JXTable has a BooleanRenderer, so
> I'd assume this would work out of the box?

Hmm, it does - have a look at the following method (in the swingx tests):

JXTreeTableModel.interactiveTestBooleanRenderer

Please let me know if that approach does not suite your needs
(preferably with a short code example demonstrating the misbehaviour)

Thanks
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

arooaroo
Offline
Joined: 2005-04-06

> Hi Andy,
>
> >
> > Why is it also that it won't display Booleans as
> checkboxes?
> > The Javadocs show that JXTable has a
> a BooleanRenderer, so
> > I'd assume this would work out of the box?
>
> Hmm, it does - have a look at the following method
> (in the swingx tests):
>
> JXTreeTableModel.interactiveTestBooleanRenderer
>
> Please let me know if that approach does not suite
> your needs
> (preferably with a short code example demonstrating
> the misbehaviour)
>

Ah, so it does! Turns out that there was something wrong with my swingx.jar. I recompiled and it worked fine! Apologies for the false accusation!

Simon, Jonathan (GMIT Repo Systems)

It seems there is a very strong vibe to keeping the JTree in the JTreeTable private to ensure the Tree and TreeTable stay in sync. I am working with some advanced rendering and display issues with a
JTreeTable. In order to accomplish the required functionality I have my own copy of the JTreeTable source in my source tree and allow access to the Jtree table renderer.

I know this is definitely not the ideal solution, but it's working for me for now. My vote is to make the Jtree accessible assuming developers wont do something to break the sync between the tree and
JTreeTable. If the decision is that it is to dangerous (which I think it might be) then there could definitely be some helper methods to allow things like setting the Jtree renderer directly from the
JTreeTable without allowing access to the Jtree itself.

My $0.02.

-jonathan

-----Original Message-----
From: jdnc-interest@javadesktop.org [mailto:jdnc-interest@javadesktop.org]
Sent: Wednesday, August 11, 2004 11:39 AM
To: jdnc@jdnc.dev.java.net
Subject: Re: RE: Setting editor/renderer for JTreeTable

Ramesh,

I have data that is currently being displayed in a JTree that I would like to use a JTreeTable for. My question is about how to make my custom rendering work with a JTreeTable. My data is logically
a tree of statuses. Each status is either a success, a warning, or a failure and correspondingly rendered as a green circle, a yellow triangle, or a red octagon. This is independent of whether the
status is composed of other statuses.

With JTree I just used
tree.setCellRenderer(new StatusTreeCellRenderer());

How should I translate this functionality?

Thanks,
Curt
---
[Message sent by forum member 'coxcu' (Curt Cox)]

http://www.javadesktop.org/forums/thread.jspa?messageID=22254&#22254

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

==============================================================================

If you are not an intended recipient of this e-mail, please notify
the sender, delete it and do not read, act upon, print, disclose,
copy, retain or redistribute it.

Click here for important additional terms relating to this e-mail.

==============================================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

rameshgupta
Offline
Joined: 2004-06-04

> It seems there is a very strong vibe to keeping the
> JTree in the JTreeTable private to ensure the Tree
> and TreeTable stay in sync. I am working with some
> advanced rendering and display issues with a
> JTreeTable. In order to accomplish the required
> functionality I have my own copy of the JTreeTable
> source in my source tree and allow access to the
> Jtree table renderer.
>
> I know this is definitely not the ideal solution, but
> it's working for me for now.

Jonathan,

Glad to hear that you got your existing code to work with JDNC!

> My vote is to make the
> Jtree accessible assuming developers wont do
> something to break the sync between the tree and
> JTreeTable. If the decision is that it is to
> dangerous (which I think it might be) then there
> could definitely be some helper methods to allow
> things like setting the Jtree renderer directly from
> the JTreeTable without allowing access to the Jtree
> itself.
>
> My $0.02.
>
> -jonathan

I think it is important to ensure safety without shutting people out of important capabilities. In this case, I'd rather expose a method to set the renderer for the hierarchical column, than expose the whole tree.

>
> -----Original Message-----
> From: jdnc-interest@javadesktop.org
> [mailto:jdnc-interest@javadesktop.org]
> Sent: Wednesday, August 11, 2004 11:39 AM
> To: jdnc@jdnc.dev.java.net
> Subject: Re: RE: Setting editor/renderer for
> JTreeTable
>
>
> Ramesh,
>
> I have data that is currently being displayed in a
> JTree that I would like to use a JTreeTable for. My
> question is about how to make my custom rendering
> work with a JTreeTable. My data is logically
> a tree of statuses. Each status is either a success,
> a warning, or a failure and correspondingly rendered
> as a green circle, a yellow triangle, or a red
> octagon. This is independent of whether the
> status is composed of other statuses.
>
> With JTree I just used
> tree.setCellRenderer(new
> (new StatusTreeCellRenderer());
>
> How should I translate this functionality?
>
> Thanks,
> Curt

Curt,

Until we add a method to set the tree cell renderer as Jonathan suggested, the simplest fix for you might be to change your own copy of JXTreeTable as follows:

private final void init(TreeTableCellRenderer renderer) {
// Temporary fix for Curt's application
renderer.setCellRenderer(newStatusTreeCellRenderer());
// The above will mask ClippedTreeCellRenderer, but that
// should not affect Curt's application.

// Continue with regular JDNC code...
this.renderer = renderer;
...
}

rameshgupta
Offline
Joined: 2004-06-04

> Until we add a method to set the tree cell renderer
> as Jonathan suggested, the simplest fix for you might
> be to change your own copy of JXTreeTable as
> follows:
>
> private final void init(TreeTableCellRenderer
> renderer) {
> // Temporary fix for Curt's application
> renderer.setCellRenderer(newStatusTreeCellRenderer());
>
> // The above will mask ClippedTreeCellRenderer, but
> that
> // should not affect Curt's application.
>
> // Continue with regular JDNC code...
> this.renderer = renderer;
> ...
> }

Now that I think about it, allowing developers to change the tree cell renderer effectively exposes the tree because the first argument to getTreeCellRenderer() is the tree itself! Just make sure that you treat this tree strictly as read-only, and don't pass it around to any other object, even for read-only access -- Instead, make copies of values if you need to!!!

Ramesh

Ramesh

evickroy
Offline
Joined: 2004-07-23

> Now that I think about it, allowing developers to
> change the tree cell renderer effectively exposes the
> tree because the first argument to
> getTreeCellRenderer() is the tree itself! Just make
> sure that you treat this tree strictly as read-only,
> and don't pass it around to any other object, even
> for read-only access -- Instead, make copies of
> values if you need to!!!
Couldn't you just drop the tree argument from the exposed method and internally forward it along with the internal tree?

Erik

rameshgupta
Offline
Joined: 2004-06-04

> > Now that I think about it, allowing developers to
> > change the tree cell renderer effectively exposes
> > the tree because the first argument to
> > getTreeCellRenderer() is the tree itself! Just
> > make sure that you treat this tree strictly as
> > read-only, and don't pass it around to any other
> > object, even for read-only access --
> > Instead, make copies of values if you need to!!!

> Couldn't you just drop the tree argument from the
> exposed method and internally forward it along with
> the internal tree?
>
> Erik

Unfortunately, it is not possible to drop the tree argument as it is part of the public API for TreeCellRenderer :-(

Ramesh

rameshgupta
Offline
Joined: 2004-06-04

> The JDNC demos have a more graphical approach to the
> tree in the treetable. There are no tree lines, and
> no visible structure. As an example, can you point me
> to where this code was implemented? It
> wasn't readily apparent when I was looking though the
> source.
>
> Thanks.
> -jonathan

All of the visual properties of the tree are driven by the treetable's visual properties. All of the public JTreeTable constructors funnel through a private constructor, which calls setShowGrid(false) to remove the horizontal and vertical lines from JTreeTable. It also sets the default intercell spacing, and then synchronizes the row height/margin with the internal tree.

The original TreeTable implementation used JTree as a renderer for the hierarchical column, and exposed the JTree. The new design uses a package-private extension of JXTree for the same purpose. The reason it is package-private is because we do not want to expose the underlying implementation details through the public api.

If you are looking for code that removes the angular lines from the tree portion, please search for "JTree.lineStyle". This will take you to the constructor for JTreeTable.TreeTableCellRenderer, which, in addition to hiding the lines, also hides the root (opposite of JTree defaults).

As you know, JTreeTable.TreeTableCellRenderer is actually an extension of JTree that it is used as a renderer for the hierarchical column in the JTreeTable. But while DefaultTableCellRenderer is capable of truncating long strings in a cell with ellipses (...) if the text does not fit in the cell, DefaultTreeCellRenderer does have this capability. So, for consistency with non-hierarchical columns, this renderer has to be replaced in JTreeTable.TreeTableCellRenderer with the private ClippedTreeCellRenderer.

So, this is how rendering is delegated for the hierarchical column: JTable delegates the cell rendering to its cell renderer, which is an instance of TreeTableCellRenderer. But TreeTableCellRenderer is itself a JTree, which delegates *its* rendering to a tree cell renderer, which happens to be an instance of ClippedTreeCellRenderer in this case.

If you are keen on custom rendering for the tree, the best strategy is to consider using highlighters.

Hope this clears things up.

Ramesh

coxcu
Offline
Joined: 2003-06-11

Ramesh,

I have data that is currently being displayed in a JTree that I would like to use a JTreeTable for. My question is about how to make my custom rendering work with a JTreeTable. My data is logically a tree of statuses. Each status is either a success, a warning, or a failure and correspondingly rendered as a green circle, a yellow triangle, or a red octagon. This is independent of whether the status is composed of other statuses.

With JTree I just used
tree.setCellRenderer(new StatusTreeCellRenderer());

How should I translate this functionality?

Thanks,
Curt