[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Changing font of Label in a Composite

Alejandro Bascuas wrote:
All,

I have a Composite that contains several Label objects in a single column. By default, they are displayed using the parent's default Font.

Each Label will be redrawn in bold during program execution at least once. I accomplish this by setting the bold font on one of them and redrawing the Composite. The downside is that when a label turns bold, it takes up more space, and part of it will get hidden under the Composite to the right.

What I need to do is have each Label compute its size as if it were bold so that the Composite sets itself to a more ideal size. My ultimate goal is to have it so that the wrapping of the labels and the Composite size is constant throughout execution.

I have a few ideas of how to do this. I would like to avoid writing a custom Layout. I figure I'd check with the forum to see what other ideas are out there.

Assuming you are using one of the SWT layouts already, you might just be overlooking the need to call layout() on the parent Composite after changing the font. layout() instructs the Composite to re-calculate everything, so it will take the new font into consideration.


Hope this helps,
	Eric


By the way, if I were doing this in more than one place, I would create a base Composite class of my own that had a method to set the font for all contained Labels and then call layout() on itself. It would need a way to track Label instances as they were added.