| [Draw2D] Setting Label size [message #81181] |
Tue, 27 May 2003 13:50  |
Eclipse User |
|
|
|
Originally posted by: a_shishkov.yahoo.com
Hello,
I have been using the following code to set the size of a Label such that it
is the minimum size needed for the label to fit all its text. It worked
fine with a draw2d.jar from a few months ago, but I have recently updated to
the latest jar and the code throws an exception.
Figure panel = new Figure();
Label label = new Label("Hello Label");
panel.add(label);
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.white);
label.setLocation(new Point(x, y));
label.setSize(label.getPreferredSize());
If I don't call setSize on the label it would come up a lot larger than the
text. With the new draw2d.jar I get the following exception on the setSize
line:
java.lang.NullPointerException
at org.eclipse.draw2d.FigureUtilities.setFont(FigureUtilities.j ava:252)
at
org.eclipse.draw2d.FigureUtilities.getTextDimension(FigureUt ilities.java:78)
at
org.eclipse.draw2d.FigureUtilities.getTextExtents(FigureUtil ities.java:131)
at org.eclipse.draw2d.Label.calculateTextSize(Label.java:215)
at org.eclipse.draw2d.Label.getTextSize(Label.java:406)
at org.eclipse.draw2d.Label.getPreferredSize(Label.java:284)
at org.eclipse.draw2d.Figure.getPreferredSize(Figure.java:620)
I am not using a layout manager because I need complete control over the
size and position of some other figures in the same panel. Why can't I get
the preferred size of the label using the latest draw2d.jar? Is there any
other way I can set the size of my label to fit all the text, but no more?
Thank you for any help.
Angel
|
|
|
| Re: [Draw2D] Setting Label size [message #81197 is a reply to message #81181] |
Tue, 27 May 2003 16:48  |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You shouldn't be setting the size of a Figure. The parent's layout manager
should do that when it lays out.
You are getting this error because the Label does no know what font to use
when measuring its text. If you add the label to its parent, it will then
be able to obtain its parent's font, and the error will not occur. This
didn't show up earlier because of a bug in FigureUtilities where it would
use some random font whenever NULL was passed in.
"Angel Shishkov" <a_shishkov@yahoo.com> wrote in message
news:bb08ej$cbd$1@rogue.oti.com...
> Hello,
>
> I have been using the following code to set the size of a Label such that
it
> is the minimum size needed for the label to fit all its text. It worked
> fine with a draw2d.jar from a few months ago, but I have recently updated
to
> the latest jar and the code throws an exception.
>
>
> Figure panel = new Figure();
> Label label = new Label("Hello Label");
> panel.add(label);
>
> label.setOpaque(true);
> label.setBackgroundColor(ColorConstants.white);
> label.setLocation(new Point(x, y));
> label.setSize(label.getPreferredSize());
>
>
>
> If I don't call setSize on the label it would come up a lot larger than
the
> text. With the new draw2d.jar I get the following exception on the setSize
> line:
>
> java.lang.NullPointerException
> at org.eclipse.draw2d.FigureUtilities.setFont(FigureUtilities.j ava:252)
> at
>
org.eclipse.draw2d.FigureUtilities.getTextDimension(FigureUt ilities.java:78)
> at
>
org.eclipse.draw2d.FigureUtilities.getTextExtents(FigureUtil ities.java:131)
> at org.eclipse.draw2d.Label.calculateTextSize(Label.java:215)
> at org.eclipse.draw2d.Label.getTextSize(Label.java:406)
> at org.eclipse.draw2d.Label.getPreferredSize(Label.java:284)
> at org.eclipse.draw2d.Figure.getPreferredSize(Figure.java:620)
>
> I am not using a layout manager because I need complete control over the
> size and position of some other figures in the same panel. Why can't I get
> the preferred size of the label using the latest draw2d.jar? Is there any
> other way I can set the size of my label to fit all the text, but no more?
>
> Thank you for any help.
>
> Angel
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04476 seconds