Centering a label horizontally and vertically [message #553202] |
Mon, 16 August 2010 12: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 #718121 is a reply to message #553202] |
Tue, 23 August 2011 06:14  |
Eclipse User |
|
|
|
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.04400 seconds