Skip to main content

[JXTreeTable] setRowHeight

19 replies [Last post]
aurlien
Offline
Joined: 2006-02-17

Hi all,

I'm using jxtreetable to display values which can be very long. So I'd like to display these values on several raws (inserting '\n' through the renderer), and I need to change the height of the concerning row.

But the method setRowHeight(int row, int rowHeight) throws UnsupportedOperationException...

Do you plan to implement this method, or do you know another way to do what I want?

Thanks,

Aurélien

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Scott Violet

JTree supports variable row heights, but in a different manner than
JTable. If the row height of a JTree is <= 0 than the renderer is
queried for the height. So, to support this a custom renderer for the
JTree portion of the JXTreeTable would be required that looks up the
value from the table.

-Scott

jdnc-interest@javadesktop.org wrote:
> The real reason why setRowHeight(int, int) is unimplemented in JXTreeTable is that JTree/JXTree didn't (and still doesn't) support setRowHeight(int, int) making it difficult to keep the table and the tree portions of treetable in sync :-(
>
> Ramesh
>
>
>>When the original JTreeTable was done JTable did not
>>have a setRowHeight(int,int). Now that it does it makes
>>sense to implement this in JXTreeTable. I suspect the
>>reason it isn't there is that Ramesh never got to it.
>>
>> -Scott
>>
>>jdnc-interest@javadesktop.org wrote:
>>
>>>Hi,
>>>
>>>
>>>
>>>>But the method setRowHeight(int row, int
>>>>rowHeight)
>>>>throws UnsupportedOperationException...
>>>>
>>>>Do you plan to implement this method, or do you
>>>>know another way to do what I want?
>>>
>>>
>>>I am not sure, what was the reason for not
>>>supporting this method
>>>originally (maybe Ramesh or Scott can answer this).
>>>But I can definitely
>>>see the need to support this. Can you please file
>>>an feature request
>>>in Issue tracker ? Thanks,
>>>
>>>Regards,
>>>Bino.
>
> ---
> [Message sent by forum member 'rameshgupta' (Ramesh Gupta)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=47477&#47477
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

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

Scott Violet

When the original JTreeTable was done JTable did not have a
setRowHeight(int,int). Now that it does it makes sense to implement
this in JXTreeTable. I suspect the reason it isn't there is that Ramesh
never got to it.

-Scott

jdnc-interest@javadesktop.org wrote:
> Hi,
>
>
>>But the method setRowHeight(int row, int rowHeight)
>>throws UnsupportedOperationException...
>>
>>Do you plan to implement this method, or do you know
>>another way to do what I want?
>
>
> I am not sure, what was the reason for not supporting this method
> originally (maybe Ramesh or Scott can answer this). But
> I can definitely
> see the need to support this. Can you please file an feature request
> in Issue tracker ? Thanks,
>
> Regards,
> Bino.
> ---
> [Message sent by forum member 'bino_george' (Bino George)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=45456&#45456
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

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

The real reason why setRowHeight(int, int) is unimplemented in JXTreeTable is that JTree/JXTree didn't (and still doesn't) support setRowHeight(int, int) making it difficult to keep the table and the tree portions of treetable in sync :-(

Ramesh

> When the original JTreeTable was done JTable did not
> have a setRowHeight(int,int). Now that it does it makes
> sense to implement this in JXTreeTable. I suspect the
> reason it isn't there is that Ramesh never got to it.
>
> -Scott
>
> jdnc-interest@javadesktop.org wrote:
> > Hi,
> >
> >
> >>But the method setRowHeight(int row, int
> >>rowHeight)
> >>throws UnsupportedOperationException...
> >>
> >>Do you plan to implement this method, or do you
> >>know another way to do what I want?
> >
> >
> > I am not sure, what was the reason for not
> > supporting this method
> > originally (maybe Ramesh or Scott can answer this).
> > But I can definitely
> > see the need to support this. Can you please file
> > an feature request
> > in Issue tracker ? Thanks,
> >
> > Regards,
> > Bino.

Patrick Wright

FWIW, I had to work on this problem many months ago when I was
integrating a JTextArea as an editor and display component for a tree
(for a discussion-board tool). There are a number of threads available
through Google Search (web or groups) that discuss how to work around
this, basically there are some "magic" API calls that can force the tree
to re-layout the height, among other things. I don't have the bookmarks
anymore, but if you search around you will find them. They are
workarounds, though, not the real thing.

HTH
Patrick

jdnc-interest@javadesktop.org wrote:
> The real reason why setRowHeight(int, int) is unimplemented in JXTreeTable is that JTree/JXTree didn't (and still doesn't) support setRowHeight(int, int) making it difficult to keep the table and the tree portions of treetable in sync :-(
>
> Ramesh
>
>
>>When the original JTreeTable was done JTable did not
>>have a setRowHeight(int,int). Now that it does it makes
>>sense to implement this in JXTreeTable. I suspect the
>>reason it isn't there is that Ramesh never got to it.
>>
>> -Scott
>>
>>jdnc-interest@javadesktop.org wrote:
>>
>>>Hi,
>>>
>>>
>>>
>>>>But the method setRowHeight(int row, int
>>>>rowHeight)
>>>>throws UnsupportedOperationException...
>>>>
>>>>Do you plan to implement this method, or do you
>>>>know another way to do what I want?
>>>
>>>
>>>I am not sure, what was the reason for not
>>>supporting this method
>>>originally (maybe Ramesh or Scott can answer this).
>>>But I can definitely
>>>see the need to support this. Can you please file
>>>an feature request
>>>in Issue tracker ? Thanks,
>>>
>>>Regards,
>>>Bino.
>
> ---
> [Message sent by forum member 'rameshgupta' (Ramesh Gupta)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=47477&#47477
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

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

Scott Violet

Patrick,

Could you outline what it is you would like to see? Do you want an API
like setRowHeight(int,int) for JTree? As I just responded to Ramesh
this functionality is available by way of a custom renderer.

-Scott

Patrick Wright wrote:
> FWIW, I had to work on this problem many months ago when I was
> integrating a JTextArea as an editor and display component for a tree
> (for a discussion-board tool). There are a number of threads available
> through Google Search (web or groups) that discuss how to work around
> this, basically there are some "magic" API calls that can force the tree
> to re-layout the height, among other things. I don't have the bookmarks
> anymore, but if you search around you will find them. They are
> workarounds, though, not the real thing.
>
> HTH
> Patrick
>
> jdnc-interest@javadesktop.org wrote:
>
>> The real reason why setRowHeight(int, int) is unimplemented in
>> JXTreeTable is that JTree/JXTree didn't (and still doesn't) support
>> setRowHeight(int, int) making it difficult to keep the table and the
>> tree portions of treetable in sync :-(
>>
>> Ramesh
>>
>>
>>> When the original JTreeTable was done JTable did not
>>> have a setRowHeight(int,int). Now that it does it makes
>>> sense to implement this in JXTreeTable. I suspect the reason it
>>> isn't there is that Ramesh never got to it.
>>>
>>> -Scott
>>>
>>> jdnc-interest@javadesktop.org wrote:
>>>
>>>> Hi,
>>>>
>>>>
>>>>
>>>>> But the method setRowHeight(int row, int
>>>>> rowHeight)
>>>>> throws UnsupportedOperationException...
>>>>> Do you plan to implement this method, or do you
>>>>> know another way to do what I want?
>>>>
>>>>
>>>>
>>>> I am not sure, what was the reason for not
>>>> supporting this method
>>>> originally (maybe Ramesh or Scott can answer this).
>>>> But I can definitely
>>>> see the need to support this. Can you please file
>>>> an feature request
>>>> in Issue tracker ? Thanks,
>>>>
>>>> Regards,
>>>> Bino.
>>
>>
>> ---
>> [Message sent by forum member 'rameshgupta' (Ramesh Gupta)]
>>
>> http://www.javadesktop.org/forums/thread.jspa?messageID=47477&#47477
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
>> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

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

Patrick Wright

Scott,

I have no current need. I was relating my experience to the person on
the thread who asked about setting row height. My point was that there
were ways to force the tree to recalculate all row heights based on the
renderer. From what I rememeber, the problem was that in the JTree
implementation there was an assumption of row heights being the same,
possibly to improve rendering time. In my case, I was using the tree to
display discussion threads, which could be from 1 to n lines long. I
could not easily determine the actual size of the renderer, and the tree
was ignoring the fact that the (custom) renderers were different
heights. I will look up the solution I coded and pass it along, in case
it helps in any way. Just wanted to point out that there were
workarounds to rowheight problems in JTree available on discussion
newsgroups.

Patrick

Scott Violet wrote:
> Patrick,
>
> Could you outline what it is you would like to see? Do you want an API
> like setRowHeight(int,int) for JTree? As I just responded to Ramesh
> this functionality is available by way of a custom renderer.
>
> -Scott

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

Scott Violet

Patrick,

JTree allows you to specify a specific row height, or have the renderer
queried for the row height. This behavior is controlled by
setRowHeight(int). A value > 0 fixs the row height of all rows, where
as a value <= 0 means the row height, for each row, is determined from
the preferred size of the renderer. If this didn't work for you I would
love a test case to try and nail what is going on.

-Scott

Patrick Wright wrote:
> Scott,
>
> I have no current need. I was relating my experience to the person on
> the thread who asked about setting row height. My point was that there
> were ways to force the tree to recalculate all row heights based on the
> renderer. From what I rememeber, the problem was that in the JTree
> implementation there was an assumption of row heights being the same,
> possibly to improve rendering time. In my case, I was using the tree to
> display discussion threads, which could be from 1 to n lines long. I
> could not easily determine the actual size of the renderer, and the tree
> was ignoring the fact that the (custom) renderers were different
> heights. I will look up the solution I coded and pass it along, in case
> it helps in any way. Just wanted to point out that there were
> workarounds to rowheight problems in JTree available on discussion
> newsgroups.
>
>
> Patrick
>
> Scott Violet wrote:
>
>> Patrick,
>>
>> Could you outline what it is you would like to see? Do you want an
>> API like setRowHeight(int,int) for JTree? As I just responded to
>> Ramesh this functionality is available by way of a custom renderer.
>>
>> -Scott
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

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

armin
Offline
Joined: 2004-10-08

I need different row sizes in the JXTreeTable and tried to set the RowHeight to zero and the preferred size of the rendered cell to the row height I want. Problem is, setRowHeight(0) throws an IllegalArgumentException in JTable and access the Tree part is not possible.

Did I missunderstood something?
Is there a way to have variable rowheight in JXTreeTable

Thanx

Armin

Scott Violet

Armin,

This has not been wired up and it's up for debate as to what should
happen. With JTable you can specify the overall row height, or the row
height for individual rows. JTree, as you know, allows an overall row
height or the row height should come from the renderer. We could allow
the row height to come from the renderer for JXTable/JXTreeTable but
that would be quite expensive in that it would have to be the max of all
columns in a particular row. If we allowed you to specify the row
height of a particular node for JXTreeTable would that be enough? Or do
you really want the max of all renderers in a particular row?

Thanks,

-Scott

jdnc-interest@javadesktop.org wrote:
> I need different row sizes in the JXTreeTable and tried to set the RowHeight to zero and the preferred size of the rendered cell to the row height I want. Problem is, setRowHeight(0) throws an IllegalArgumentException in JTable and access the Tree part is not possible.
>
> Did I missunderstood something?
> Is there a way to have variable rowheight in JXTreeTable
>
> Thanx
>
> Armin
> ---
> [Message sent by forum member 'armin' (Armin)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=68194
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

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

armin
Offline
Joined: 2004-10-08

Hi Scott,

thanx for the fast reply.

In fact I calculate the max height of a table row on model change now. It is clear this makes sense only if the model is not that big.

To answer your question. Why not make it configurable to calc individual row heights? Everybody using this feature knows, that this slows down rendering. But that's better than not having this (in my opinion) important feature.

For me it is ok to specify the row height for a particular node

Armin

Scott Violet

Armin,

Thanks for the feedback.

-Scott

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

gherr
Offline
Joined: 2006-02-14

Hi Scott,

has there been any progress on this topic since the last release?

I would like to create a JXTreeTable with rows having different heights. To my understanding, the proposed new feature would support this.

Regards.

Gabor

Scott Violet

Gabor,

Sorry to say nothing has been done at this time. We're all currently
soaked trying to wrap out JavaOne demos...

-Scott

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

gherr
Offline
Joined: 2006-02-14

Scott,

I'd like to add this feature to JXTreeTable myself. From
the previous discussion, it seems that simply implementing getPreferredSize in ClippedTreeCellRenderer, which obtains the current line height from JXTreeTable, would do it. The only question is, how to determine the current line number within the cell renderer? Can you give me a hint?

Gabor

Scott Violet

jdnc-interest@javadesktop.org wrote:
> Scott,
>
> I'd like to add this feature to JXTreeTable myself.

Excellent!

> From
> the previous discussion, it seems that simply implementing
> getPreferredSize in ClippedTreeCellRenderer,

The other key thing is to make sure the row height of the tree is -1.
That's simple though, just search for calls to setRowHeight in JXTreeTable.

> which obtains the current
> line height from JXTreeTable, would do it. The only question is, how to
> determine the current line number within the cell renderer? Can you give
> me a hint?

In ClippedTreeCellRenderer you will want to override the
TreeCellRenderer method:

Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus);

That gives you the row.
Let me know if you get stuck or need help and I'll do what I can.

-Scott

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

gherr
Offline
Joined: 2006-02-14

Hi Scott,

unfortunately, it turned out that the implementation is not that simple and I got stuck now...

The TreeCellRenderer heavily relies on the fact that the table consists of equally sized rows, eg. when calculating the offset to translate graphics for its paint method. IMHO the current implementation is wrong, as it assumes that row heights are calculated differently in JTree and JTable, because JTable has row margins. There is a lot of code in JXTreeTable to reconcile these differences. This is not necessary, as JTree already includes the row margin into its height calculations. As a first step, I removed this margin calculations from the cell renderer and changed the paint method to delegate the offset calculation to JTable, so it can take different row heights into account. For fixed row sizes this works fine now.

After some debugging, I realized that JTree queries its cell renderer for the current row height (in case if row height <= 0) by calling getPrefferedSize(). Somehow this is done only a very few times and not with every call to getTreeCellRendererComponent(), probably after the layout has been invalidated. So after expanding some nodes, which have a different row height in the table, the tree does not query the renderer for the preffered height and the tree view gets out of sync with the table.

Do you have any ideas, how to solve this?

Thanks.

Gabor

Scott Violet

Gabor,

jdnc-interest@javadesktop.org wrote:
> Hi Scott,
>
> unfortunately, it turned out that the implementation is not that simple
> and I got stuck now...

The devil is always in the details!

> The TreeCellRenderer heavily relies on the fact that the table consists
> of equally sized rows, eg. when calculating the offset to translate
> graphics for its paint method. IMHO the current implementation is wrong,

Agreed. Long term JXTreeTable should not directly use a JTree. Using
one of the AbstractLayoutCache implementations directly and manage
expanded state would simplify a number of things.

As to this particular problem, yes, you'll need to modify paint to
translate to the approriate place. Hopefully you could use getCellRect,
or as you suggest one of the tree equivalents.

> as it assumes that row heights are calculated differently in JTree and
> JTable, because JTable has row margins. There is a lot of code in
> JXTreeTable to reconcile these differences. This is not necessary, as
> JTree already includes the row margin into its height calculations. As a
> first step, I removed this margin calculations from the cell renderer
> and changed the paint method to delegate the offset calculation to
> JTable, so it can take different row heights into account. For fixed row
> sizes this works fine now.

That sounds reasonable.

> After some debugging, I realized that JTree queries its cell renderer
> for the current row height (in case if row height <= 0) by calling
> getPrefferedSize(). Somehow this is done only a very few times and not
> with every call to getTreeCellRendererComponent(), probably after the
> layout has been invalidated. So after expanding some nodes, which have a
> different row height in the table, the tree does not query the renderer
> for the preffered height and the tree view gets out of sync with the table.

Yes, the preferred size is cached. JTree will update the cache when the
appropriate TreeModelEvent is sent. When someone invokes
setRowHeight(int,int) you'll need to send a TreeModelEvent so that the
tree correctly updates its internal caches. This won't be easy though,
in that TreeModel doesn't have a public method for you to call to notify
listeners like you'll need, and the object you need to update is buried
in the UI. This best thing I can think of is to wrap the supplied
TreeTableModel with your own that has public method for notifying
TreeModelListeners of changes. That way when someone does a
setRowHeight(int,int) you can cause the appropriate event to be sent.

I've commented to Richard and Ramesh about the desire to redo
JXTreeTables implementation. I currently have too much on my plate and
won't be able to get to it for a while.

-Scott

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

bino_george
Offline
Joined: 2003-06-16

Hi,

> But the method setRowHeight(int row, int rowHeight)
> throws UnsupportedOperationException...
>
> Do you plan to implement this method, or do you know
> another way to do what I want?

I am not sure, what was the reason for not supporting this method
originally (maybe Ramesh or Scott can answer this). But
I can definitely
see the need to support this. Can you please file an feature request
in Issue tracker ? Thanks,

Regards,
Bino.

aurlien
Offline
Joined: 2006-02-17

ok, it's done.

Thanks!