So it appears you can actually set the row height of a SWT table despite me previously saying you couldn’t. The caveat is that it cannot be set on a per row basis. Row height is set using a Listener for SWT.MeasureItem and then setting the height property of the supplied event object as shown below.
// resize the row height using a MeasureItem listener table.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event event) { // height cannot be per row so simply set event.height = 67; } });
If need be you could compute the actual height using the GC.stringExtent(String).y and simply set to the biggest value you encounter.
Information from Custom Drawing Table and Tree Items at Eclipse.org.
How about setting the Tooltip to be the entire text?
LikeLike
You mean because the text is being truncated from v. 1.0.1? Well I solved the row height issue this morning and that would alleviate the need for a tooltip.
LikeLike
Yeah, the wrapping works fine in 1.0.1. Some larger entries still get truncated though.
I was just thinking that if you are going to size the table rows to accomodate the largest entry then one large entry could ‘mess up’ the table for all the normal sized entries.
I was suggesting that if you picked a ‘reasonable’ height for the rows and added a tooltip then large posts could be read by just moving the mouse over the entry, without having to resize anything.
LikeLike
That’s a good idea. In v. 1.0.2 I’m setting a fixed height to accommodate the largest post possible.
LikeLike
i want to do the same with Grid nebula.
i want it to support newline character so i can insert multiple rows in each cell.
LikeLike
Good idea!
I’ve calculated the text height:
FontMetrics fm = new GC(Display.getCurrent()).getFontMetrics();
int height = fm.getHeight();
LikeLike
hi thank you for your code buddy. i really tried hard to find out specifying the height of row. the code worked .thanks again
LikeLike
Thank you very much for posting this!
LikeLike
You must dispose the GC, otherwise you are opening the door for a resounce leak.
LikeLike
Will this still work, if we maually expands or shrinks the column width of the table ?
I mean if we manually shrink the column width, the row height will grow and if we expand the column width, the row height will fall.
LikeLike
Well when I did it the row could only grow in size so you could make it higher as the column was made smaller but it wouldn’t become smaller when the column was made wider. Only way I’ve found to do that is by writing my own table component which I’ve done since then.
LikeLike
Is there any way by which i can change the color of the Grid Line Seperator between the rows?
LikeLike
Not that I know of. In effect it’s the underlying OS widget you’re using so I guess not.
LikeLike
Thank you for your simple code sample to set row height. Very easy to try
LikeLike