Hi,
I have problem with a piece of code (see below). When the text is rotated on
my panel it seems that the coordinate system is corrupt. If I put something
on x,y = 100, 200 it looks that the object is put somewhere else. I think it
has to do with the rotation. How can i go back to the norm coordinate
system/
PS : The rotation works fine for the first time
Johan
void paintComponent() {
Graphics2D g2 = (Graphics2D)g;
AffineTransform af = new AffineTransform();
af.translate(100.,50.);
af.rotate(Math.PI / 2);
FontRenderContext renderContext = new
FontRenderContext(null, false, false);
g2.transform(af);
TextLayout layout = new TextLayout("This text is rotated",
g2.getFont(), renderContext );
layout.draw(g2, 0, 0);
}
a24900@googlemail.com - 13 Oct 2007 07:33 GMT
> Hi,
>
> I have problem with a piece of code (see below). When the text is rotated on
> my panel it seems that the coordinate system is corrupt.
The coordinate system is not corrupt, it is rotated. Reset it to its
original specs and it behaves like it originally did.
Andrew Thompson - 13 Oct 2007 07:48 GMT
...
>I have problem with a piece of code (see below).
Why are you wasting your time, and our bandwith,
posting these rubbish snippets. Not only is this
incompilable because it is incomplete, but it is not
even the code being used. I can infer that because..
>void paintComponent() {
> Graphics2D g2 = (Graphics2D)g;
D:\RotatedTextPanel.java:N: cannot find symbol
symbol : variable g
location: class RotatedTextPanel
Graphics2D g2 = (Graphics2D)g;
^
Note also that the method you are attempting to
override there, is public.
Why not progress this by posting an SSCCE?
<http://www.physci.org/codes/sscce.html>

Signature
Andrew Thompson
http://www.athompson.info/andrew/
John Burton - 13 Oct 2007 08:16 GMT
> ..
>>I have problem with a piece of code (see below).
[quoted text clipped - 3 lines]
> incompilable because it is incomplete, but it is not
> even the code being used. I can infer that because..
Please don't waste our time and bandwidth posting rubbish that doesn't even
attempt to help the orignal poster.
The problems is that you're not getting a fresh Graphics object each time
the paint is called, it an retain the transformation from the previous time.
You need to either reset the transformations before you return on instead
get a copy of the Graphics object using something like
Graphics2D g2Copy = (Graphics2D)g.create();
and work with that instead.
Probably best to dispose of the copy at the end of the method
g2Copy.dispose()
Bruintje Beer - 13 Oct 2007 09:12 GMT
>> ..
>>>I have problem with a piece of code (see below).
[quoted text clipped - 17 lines]
> Probably best to dispose of the copy at the end of the method
> g2Copy.dispose()
Hi,
thanks, using a copy was the trick
Johan
Bruintje Beer - 13 Oct 2007 09:15 GMT
> ..
>>I have problem with a piece of code (see below).
[quoted text clipped - 18 lines]
> Why not progress this by posting an SSCCE?
> <http://www.physci.org/codes/sscce.html>
I am interrested in solving my problem and do not want to put a complete
java program here. I understand that it needs several import etc to get this
working.
I find it very stupid if you try this piece of code and try to run. Every
idiot understand this is not a complete java program. So stick to the
question. In fact you did not give a solution, maybe yo not understand java.
The poster John Burton has a good solution.
Johan
Roedy Green - 13 Oct 2007 11:19 GMT
>I find it very stupid if you try this piece of code and try to run. Every
>idiot understand this is not a complete java program. So stick to the
>question. In fact you did not give a solution, maybe yo not understand java.
>The poster John Burton has a good solution.
If you post a SSCCE it makes it much easier for others to explore your
problem. You will get more responses and higher quality ones.
See http://mindprod.com/jgloss/sscce.html
Be careful about biting the hand attempting to feed you, even when
that hand is connected to a scolding mouth. You can find yourself
quickly killfiled by people other than the scolder.
The reason is simple. They don't want to be snapped at too if they
produce a less than perfect response for your highness.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 13 Oct 2007 21:27 GMT
"Bruintje Beer" wrote, quoted or indirectly quoted someone who said :
>> I find it very stupid if you try this piece of code and try to run. Every
>> idiot understand this is not a complete java [sic] program. So stick to the
>> question. In fact you did not give a solution, maybe yo [sic] not understand java.
>> The poster John Burton has a good solution.
I see no reason for you to insult Andrew. He didn't insult you. You asked
for our help, remember? You might try being less rude.

Signature
Lew
Bruintje Beer - 14 Oct 2007 06:28 GMT
> "Bruintje Beer" wrote, quoted or indirectly quoted someone who said :
>>> I find it very stupid if you try this piece of code and try to run.
[quoted text clipped - 4 lines]
> I see no reason for you to insult Andrew. He didn't insult you. You
> asked for our help, remember? You might try being less rude.
No hard feelings
Johan
Roedy Green - 14 Oct 2007 11:48 GMT
>I see no reason for you to insult Andrew. He didn't insult you. You asked
>for our help, remember? You might try being less rude.
"Why are you wasting your time, and our bandwidth,
posting these rubbish snippets."
~ Andrew
Andrew was doing his usual haze the newbies thing that at times tempts
to me have contract put out on him.
It is no wonder newbies snap back at his needlessly sharp barbs.
However my comments about not complaining about responses to requests
for help no matter how socially inept still stands.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 14 Oct 2007 18:18 GMT
>> I see no reason for you to insult Andrew. He didn't insult you. You asked
>> for our help, remember? You might try being less rude.
[quoted text clipped - 10 lines]
> However my comments about not complaining about responses to requests
> for help no matter how socially inept still stands.
I saw no comment from Andrew about the poster, only the code. And he had a point.
I agree with you, Roedy. Even to the rudest of posters it is more high-minded
to respond high-mindedly. I just don't think we should rename this group
comp.lang.java.dont.step.on.my.namby.pamby.feelings.

Signature
Lew
Roedy Green - 13 Oct 2007 09:47 GMT
>: The rotation works fine for the first time
see http://mindprod.com/jgloss/affinetransform.html
for sample code to save and restore the transform.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com