|
Re: a way to restrict the size of Labels? [message #186952 is a reply to message #185988] |
Thu, 07 July 2005 19:22 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
Subclass FlowLayout and enforce the size restrictions there.
"Damian" <damian_biollo@hotmail.com> wrote in message
news:da1v2b$oe2$1@main1.eclipse.org...
> Hi there,
>
> I have a Label figure which I would like to impose a minimum size and
> maximum size upon.
> For example, I want the figure to be between 50 and 200 pixels wide. If
the
> label text is too long to fix within 200 pixels, then I want it to display
> the "..." ellipses to indicate the truncation.
>
> The label is being used within a Figure which has a horizontal flow
layout.
> It seems that in a flow layout, the size of the label is totally
determined
> by the result of getPreferredSize (please correct me if I'm mistaken; I
> tried "setMinimumSize" and "setMaximumSize" to no avail).
>
> The problem is that I can't seem to get both behaviours -- a maximum size
> limit and the ellipses to show truncation -- mainly because the GEF
> algorithm to determine whether to show "..." depends on getPreferredSize.
>
> Is there a *nice* way to solve this issue?
>
>
> Below is the code that I implemented on the label to get it to appear
within
> my size constraints.
>
> Thanks.
>
> Label label = new Label ()
> {
> public Dimension getPreferredSize (int wHint, int hHint)
> {
> // Force this label to be bigger than the default min size
> and smaller than the max
> Dimension size = new Dimension (super.getPreferredSize
> (wHint, hHint));
> size.width = Math.max (size.width, minLabelWidth);
> size.width = Math.min (size.width, maxLabelWidth);
> return size;
> }
> };
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03102 seconds