JGoLinkLabel's vertical text alignment

Greetings again,

Is there any way of aligning vertically a text inside a link label? I’ve changed a labels height to 32px and text is aligned to top. Thanks in advance.

The labels on a JGoLabeledLink can be any JGoObject.

Take a look at the RotText subclass of JGoText defined in the Demo1 sample application. If you use this as your link label and set the rotation angle to 270, you’ll get a vertically rotated link label.

For example:

JGoBasicNode n1 = new JGoBasicNode("aaa");
n1.setLocation(50, 50);
JGoBasicNode n2 = new JGoBasicNode("bbb");
n2.setLocation(200, 100);
JGoLabeledLink l1 = new JGoLabeledLink(n1.getPort(), n2.getPort());
RotText midLabel = new RotText();
midLabel.setText("Sample Label");
midLabel.setAngle(270);
l1.setMidLabel(midLabel);
goView.getDocument().add(n1);
goView.getDocument().add(n2);
goView.getDocument().add(l1);

I think i’m misunderstood. I mean aligning at center in means of vertical direction.

It becomes like this


| ABC |
| |

but i want it like this:


| |
| ABC |

Thanks in advance.

In general, you do this by specifying the SpotLocation of the label in your node, and this is typically done in the LayoutChildren() method of your node.

Several of the pre-defined node classes make this easy. For example, JGoBasicNode has a setLabelSpot() method. So you could easily create a rectangular node with a centered label as follows:

JGoBasicNode tnode = new JGoBasicNode("rectangular basic node");
tnode.setLabelSpot(JGoObject.Center);
tnode.setDrawable(new JGoRectangle());
tnode.setLocation(100, 100);
goView.getDocument().add(tnode);

Thanks, but if labels parent is a labeled link as i mentioned in title? Is there a way to center text of a link label vertically?

Should i override setAlignment method so it would not always uses top side:

public static final int ALIGN_LEFT = TopLeft; //to mid left
public static final int ALIGN_CENTER = TopCenter; //to mid
public static final int ALIGN_RIGHT = TopRight; //to mid right

switch (align) {
default:
case Center: align = ALIGN_CENTER; break;
case TopLeft: align = ALIGN_LEFT; break;
case TopCenter: align = ALIGN_CENTER; break;
case TopRight: align = ALIGN_RIGHT; break;
case RightCenter: align = ALIGN_RIGHT; break;
case BottomRight: align = ALIGN_RIGHT; break;
case BottomCenter: align = ALIGN_CENTER; break;
case BottomLeft: align = ALIGN_LEFT; break;
case LeftCenter: align = ALIGN_LEFT; break;
}

One typically does not set the height of a JGoTextObject. The JGoTextObject sets the height itself based on the text string, font, etc… Similarly, there are no options for centering the text vertically in the space because the allocated space is typically just enough to hold the text.

However, the label on a JGoLabeledLink can actually be any JGoObject, so you could create your own label class that was a JGoRectangle with a JGoText object centered within it.

I’m not sure exactly what you’re trying to achieve, but if your real goal is to position the labels on your JGoLabeledLink differently, another alternative would be to override the JGoLabeledLink positionLabels() method.