Skip to main content

strange behaviour (setLocation)

2 replies [Last post]
iam_peter
Offline
Joined: 2009-05-30

hello,

i tried to get several node (SGText) to set its location to (0,10), here is the code:

...
public Node extends SGText...
...

Node node = new Node(String value);

double x = 0;
double y = 10;

node.setLocation(new Point2D.Double(x, y));

System.out.println(node.getValue() + " " + node.getBounds() + " " + x + " " + y);

Console:
value java.awt.geom.Rectangle2D$Float[x=-2.0,y=1.0,w=41.0,h=13.0] 0.0 10.0
value java.awt.geom.Rectangle2D$Float[x=-2.0,y=-12.0,w=75.0,h=25.0] 0.0 10.0

you see that the x and y coordinates from the bounds of my SGText objaect are not the coordinates i want.
why does this happen?

regards
peter

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

See the SGText.setVerticalAlignment method. The default is BASELINE
which means that english text characters will rise up vertically above
that coordinate. I imagine you want VAlign.TOP instead...

...jim

scenario@javadesktop.org wrote:
> hello,
>
> i tried to get several node (SGText) to set its location to (0,10), here is the code:
>
> ...
> public Node extends SGText...
> ...
>
> Node node = new Node(String value);
>
> double x = 0;
> double y = 10;
>
> node.setLocation(new Point2D.Double(x, y));
>
> System.out.println(node.getValue() + " " + node.getBounds() + " " + x + " " + y);
>
> [b]Console:[/b]
> [i]value[/i] java.awt.geom.Rectangle2D$Float[x=-2.0,y=1.0,w=41.0,h=13.0] 0.0 10.0
> [i]value[/i] java.awt.geom.Rectangle2D$Float[x=-2.0,y=-12.0,w=75.0,h=25.0] 0.0 10.0
>
> you see that the x and y coordinates from the bounds of my SGText objaect are not the coordinates i want.
> why does this happen?
>
> regards
> peter
> [Message sent by forum member 'iam_peter' (iam_peter)]
>
> http://forums.java.net/jive/thread.jspa?messageID=352488
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
> For additional commands, e-mail: dev-help@scenegraph.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
For additional commands, e-mail: dev-help@scenegraph.dev.java.net

iam_peter
Offline
Joined: 2009-05-30

hello,

thanks for your reply, but it doesnt fix the problem.
the vertical align is not the only problem, the x-coordinate is wrong, too.
i tried all VAlign values, but with the same result.

i put in 0 for he x coordinate, some text nodes are positioned at x = 0, other positioned at x = 2.34375.

i think it depends on the textsize, but dont know how to set the nodes in the right position.

Message was edited by: iam_peter