I am Implementing the paintComponent method where I use the Graphics drawString method but the Strings are upside down.

gdkinney_2
gdkinney_2 used Ask the Experts™
on
I am Implementing the paintComponent method where I use the Graphics drawString method but the Strings are upside down.

I am also using

g2d.translate(0, getHeight());
g2d.scale(scaleX, -scaleY);

so that the origin is the lower left corner instead of the upper left corner.  This is because I want to add zooming both in and out by changing the magnitude of the numbers in the scale method call.  How can I do this and make my drawString draw the Strings right side up?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Java Developer
Top Expert 2010
Commented:
> g2d.scale(scaleX, -scaleY);

try:

g2d.scale(scaleX, scaleY);

Author

Commented:
I did but then when I implement zooming in and out by changing the magnitude of scaleX and scaleY the zooming occurs relative to the upper left corner when I use:

g2d.scale(scaleX, scaleY);

they want the origin to be the lower left corner and have zooming occur relative to the lower left corner by using:

g2d.scale(scaleX, -scaleY);

It seems that I can not have both at the same time namely:

1) Origin in lower left corner so that zooming occurs relative to lower left corner
by using
g2d.scale(scaleX, -scaleY);

2) And have drawString draw with characters right side up.

This is what my users want though both of these at the same time.  Can it be done?
Top Expert 2016
Commented:
The following should work fine
	    g2d.translate(0, getHeight());
	    g2d.scale(scale, scale);

Open in new window

Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
Thanks CEHJ

That worked!
Top Expert 2016

Commented:
:-)
Mick BarryJava Developer
Top Expert 2010

Commented:
Why did you accept that comment? Its the same as what I already suggested.

Author

Commented:
Objects

Your right I apologize I should have given you the points probably.  I think I had taken out the line

g2d.translate(0, getHeight());

when I tried your solution so it did not work at the time.  My fault sorry about that.
Top Expert 2016

Commented:
Please feel free to reassign the points

Author

Commented:
Decided to split the points on this one because even though CEHJ's solution was after Object's solution it did contain the translate line.  Hopefully everyone will be happy with this.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial