Refresh Label of a Shape (Extended ShapeExample) [message #222420] |
Mon, 04 September 2006 16:54 |
Eclipse User |
|
|
|
Originally posted by: tobias.brueggendick.prostep.com
Hello,
i'm extending the ShapeExample ATM. Now i want to have a label which
includes the text of a shape. The Text must be in the middle of the shape
and here's the problem. At the creation it is no problem. When the Shape is
moved it is too no problem, but when the shape is only resize there the
label isn't anymore in the middle. My calculations for the lable are:
private void setLabelbounds() {
Label temp = (Label) getFigure().getChildren().get (0);
Rectangle bounds = this.getFigure().getBounds();
int y = bounds.y + (bounds.height - 25) / 2;
temp.setLocation(new Point(bounds.x, y));
temp.setSize(bounds.width, 25);
temp.revalidate();
}
I call this method in refreshVisuals().
As anybody an idea or can help me?
Best Regards
Tobias
|
|
|
|
Re: Refresh Label of a Shape (Extended ShapeExample) [message #222442 is a reply to message #222427] |
Tue, 05 September 2006 13:51 |
Eclipse User |
|
|
|
Originally posted by: tobias.brueggendick.prostep.com
I found a other solution but i had the tip of using some other Layout in
back of my mind. My Solution is relative simple. For every Figure i use i
create a label in the Figure itself. Every Figuer i want to have a label
in the middle of it, has a variable of the Type Label (Draw2d). Then the
label is initialized in the Method fillShape, there i set the bounds by
getbounds() of the figure.
At least there was one Problem. When i resize the figure a new Label is
created. The solution again was simple. I initialise the label only once
by requesting if the variable is null or not. If it is initialized it can
never be null. Voila now every Shape Display his name in the middle of its
figure. I even don't need to change my functions for DirectEdit which i
created before.
|
|
|
Powered by
FUDForum. Page generated in 0.08536 seconds