Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » auto row resize
auto row resize [message #1408065] Thu, 14 August 2014 06:33 Go to next message
Gal Rogozinski is currently offline Gal RogozinskiFriend
Messages: 40
Registered: June 2014
Member
Hey,
When I change the calculateByTextHeight flag of TextPainter I have my grid rows automatically resized to a larger height if neccessary.

What should change in the following code that is part of the paintCell method so that the row will also automatically resize down to a smaller size?

//if the content height is bigger than the available row height
			//we're extending the row height (only if word wrapping is enabled)
			int contentHeight = (fontHeight * numberOfNewLines) + (spacing*2);
			int contentToCellDiff = (cell.getBounds().height - rectangle.height);
	
			if (performRowResize(contentHeight, rectangle)) {
				ILayer layer = cell.getLayer();
				layer.doCommand(
						new RowResizeCommand(
								layer, 
								cell.getRowPosition(), 
								contentHeight + contentToCellDiff));
			}

/**
	 * Checks if a row resize needs to be triggered.
	 * @param contentHeight The necessary height to show the content completely
	 * @param rectangle The available rectangle to render to
	 * @return <code>true</code> if a row resize needs to be performed, <code>false</code> if not
	 */
	protected boolean performRowResize(int contentHeight, Rectangle rectangle) {
		return ((contentHeight > rectangle.height) && calculateByTextHeight);
	}


Thanks!
Re: auto row resize [message #1408076 is a reply to message #1408065] Thu, 14 August 2014 07:12 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Use the AutomaticRowHeightTextPainter (hope it's the correct name) to achieve shrinking too.

Note that this might cause strange behavior when used with multiple columns
Re: auto row resize [message #1408086 is a reply to message #1408076] Thu, 14 August 2014 07:53 Go to previous messageGo to next message
Gal Rogozinski is currently offline Gal RogozinskiFriend
Messages: 40
Registered: June 2014
Member
Well I do have multiple columns... This doesn't work well. It doesn't enlarge the height of the row enough and the text is cut off (this is a direct result of overriding the PerformRowResize method). If I could make it grow larger this would be great.

Also,is there anything I can do without enabling text wrap?
Re: auto row resize [message #1408095 is a reply to message #1408086] Thu, 14 August 2014 08:03 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
If you override methods yourself, you need to fix it yourself. I can't help you with that.

And I don't understand what you mean with your last question. Wrapping should be enabled in case text should wrap if the column is not wide enough. Without there is no automatic wrapping and only line breaks and new lines will cause increased height.
Re: auto row resize [message #1408135 is a reply to message #1408095] Thu, 14 August 2014 10:19 Go to previous messageGo to next message
Gal Rogozinski is currently offline Gal RogozinskiFriend
Messages: 40
Registered: June 2014
Member
Thanks for the answers!

1) AutomaticRowHeightTextPainter overrides PerformRowResize not me.

2) Allow me to clarify my question. I have 2 values that I want to display in 2 distinct cell in different rows.

a) I am a sentence with
a new line character
b) I am extremely long I am extremely long I am extremely long I am extremely long I am extremely long I am extremely long I am extremely long I am extremely long.

Now I want only value (a) to increase row height.
Now calculateByTextHeight flag does increase the row height. However if the table changes dynamically (due to filters in my case) the row doesn't scale back down accordingly Sad.
Using AutomaticRowHeightTextPainter totally messes things up.

Can you please help?
Re: auto row resize [message #1408158 is a reply to message #1408135] Thu, 14 August 2014 11:23 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
The painter only knows the cell it paints. If you use the painter for both columns things mess up. I said that before.

If you need something that takes other cells also into account you need to implement your own painter and find a way to register the current biggest row height. And of course the resize should only be executed when the last column is rendered. Otherwise it will result in flickering.

There is a reason why we don't support such a behavior out of the box.
Previous Topic:-please delete-
Next Topic:Is it possible drag the row header size??
Goto Forum:
  


Current Time: Thu Mar 28 15:48:52 GMT 2024

Powered by FUDForum. Page generated in 0.02792 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top