JGoBasicNode label allignment

Hi,

I’m using a JGoBasicNode with setLabelSpot(JGoBasicNode.Center) and setting allignment of label to left; setAlignment(JGoText.ALIGN_LEFT). This allignment code does not work, i’ve tried changing label spot and many things but cant’t succeed. Is that possible to allign a text in a JGoBasicNode which has a label spot with center value?

The following code should work:

<span =“apple-tab-span”="" style=“white-space:pre”> JGoBasicNode n = new JGoBasicNode(“line 1\nline 2 is the longest of the 3 lines\nline 3 is medium long”);
<span =“apple-tab-span”="" style=“white-space:pre”> n.getLabel().setMultiline(true);
<span =“apple-tab-span”="" style=“white-space:pre”> n.setLocation(100, 100);
<span =“apple-tab-span”="" style=“white-space:pre”> n.setLabelSpot(JGoObject.Center);
<span =“apple-tab-span”="" style=“white-space:pre”> n.getLabel().setAlignment(JGoText.ALIGN_LEFT);
<span =“apple-tab-span”="" style=“white-space:pre”> this.goView.getDocument().add(n);

In fact, yes this works for me too. However, when i have changed creatDrawable like this:

@Override
public JGoDrawable createDrawable(JGoPort p)
{
<span =“Apple-tab-span” style=“white-space:pre”> JGoDrawable e = new JGoRoundRect();
<span =“Apple-tab-span” style=“white-space:pre”> Dimension d = new Dimension(7, 7);
<span =“Apple-tab-span” style=“white-space:pre”> e.setSize(p.getWidth() + 2 * d.width, p.getHeight() + 2 * d.height);
<span =“Apple-tab-span” style=“white-space:pre”> e.setSelectable(false);
<span =“Apple-tab-span” style=“white-space:pre”> e.setResizable(false);
<span =“Apple-tab-span” style=“white-space:pre”> e.setBrush(JGoBrush.white);
<span =“Apple-tab-span” style=“white-space:pre”> return e;
}

text can’t be alligned left. Is this a bug or am i missing something? Thanks.

This is the code for my TextNode (i want one port at center, thats why i’m using basicnode):

public MyTextNode(String text)
{
<span =“Apple-tab-span” style=“white-space:pre”> super(text);
<span =“Apple-tab-span” style=“white-space:pre”> setLabelSpot(Center);
<span =“Apple-tab-span” style=“white-space:pre”> getLabel().setWrapping(true);
<span =“Apple-tab-span” style=“white-space:pre”> getLabel().setMultiline(true);
<span =“Apple-tab-span” style=“white-space:pre”> getLabel().setAlignment(JGoText.ALIGN_LEFT);
<span =“Apple-tab-span” style=“white-space:pre”> getLabel().setWrappingWidth(getWidth());
<span =“Apple-tab-span” style=“white-space:pre”> setResizable(true);
<span =“Apple-tab-span” style=“white-space:pre”> setAutoResize(false);
}

Your override of createDrawable is no problem. If you simply add that override, your node will look as follows:

The problem is in your override of the constructor. You can’t set both Wrapping and Multiline to true. If you do, wrapping will override the multiline alignment. Also, you can’t set AutoResize to false on a JGoBasicNode. If you look at the source code for JGoBasicNode, you’ll see that the initCommon method sets Resizable to true and AutoResize to false whenever the constructor is called, and these values are necessary to get the standard JGoBasicNode appearance and behavior.

That’s right. Thanks! Could you give me a hint about alligning text to left again, after editing the label? Becouse when i edited text, it alligns to center.

The easiest approach is probably to override layoutChildren() as follows:

public void layoutChildren(JGoObject childchanged) {
super.layoutChildren(childchanged);
getLabel().setAlignment(JGoText.ALIGN_LEFT);
}

Thanks a lot.