Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » a way to restrict the size of Labels?
a way to restrict the size of Labels? [message #185988] Thu, 30 June 2005 23:26 Go to next message
Damian Biollo is currently offline Damian BiolloFriend
Messages: 19
Registered: July 2009
Junior Member
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;
}
};
Re: a way to restrict the size of Labels? [message #186952 is a reply to message #185988] Thu, 07 July 2005 19:22 Go to previous message
Eclipse UserFriend
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;
> }
> };
>
>
Previous Topic:Benefits of draw2D over drawing with SWT
Next Topic:The editpart match problem between different two editors after editor reloading
Goto Forum:
  


Current Time: Mon Dec 02 21:09:45 GMT 2024

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

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

Back to the top