Centering a label horizontally and vertically [message #553202] |
Mon, 16 August 2010 16:36 |
Eclipse User |
|
|
|
Originally posted by: templth.yahoo.fr
Hello,
I want to center a label horizontally. I use the BorderLayout layout in
order to put the label in the center area but the label isn't completely
centered. In fact, it lacks the setting of the setAlignment method on
the corresponding WrappingLabel...
fFigureNameLabel = new WrappingLabel();
fFigureNameLabel.setText("");
fFigureNameLabel.setAlignment(PositionConstants.CENTER);
this.add(fFigureNameLabel, BorderLayout.CENTER);
Is it possible to specify something within the graph model in order to
have the setAlignment line generated by GMF? I saw the AlignmentFacet
element under the DiagramLabel but it doesn't seem to achieve that...
Thanks very much in advance for your answers!
Thierry
|
|
|
|
Re: Centering a label horizontally and vertically [message #554307 is a reply to message #553304] |
Sat, 21 August 2010 08:23 |
Eclipse User |
|
|
|
Originally posted by: templth.yahoo.fr
Hello Rob,
Thanks very much for the hint. I'll do like that...
Thierry
> Hello Thierry,
>
> the best thing to do would be to adapt the gmf generator template that
> misses to generate the right code for you. There you would have access
> to the gmfgen model data and could get the generator to add the missing
> code.
>
> Rob
|
|
|
Re: Centering a label horizontally and vertically [message #718121 is a reply to message #553202] |
Tue, 23 August 2011 10:14 |
vinay Messages: 4 Registered: August 2011 |
Junior Member |
|
|
Hello,
To get the label centered vetically and horizontally you just make the following changes to your code.
In EditPart Constructor write this code
this.setLayoutManager(new StackLayout() {
public void layout(IFigure figure) {
Rectangle r = figure.getClientArea();
List children = figure.getChildren();
IFigure child;
Dimension d;
for (int i = 0; i < children.size(); i++) {
child = (IFigure)children.get(i);
d = child.getPreferredSize(r.width, r.height);
d.width = Math.min(d.width, r.width);
d.height = Math.min(d.height, r.height);
Rectangle childRect = new Rectangle(
r.x + (r.width - d.width)/2,
r.y + (r.height - d.height)/2,
d.width,
d.height);
child.setBounds(childRect);
}
}
});
then
fFigureNameLabel = new WrappingLabel();
fFigureNameLabel.setText("");
fFigureNameLabel.setAlignment(PositionConstants.CENTER);
this.add(fFigureNameLabel);
|
|
|
Powered by
FUDForum. Page generated in 0.03288 seconds