I want to set up a mathematical (where y grows up not down) coordinate space from (-1, -1) to (+1, +1) and have it fit in the window regardless of the window size.

I am using an anonymous JComponent subclass in Java SE 7 and casting the incoming Graphics in paintComponent to Graphics2D and then drawing on the Graphics2D

But the Graphics2D is set to a computer coordinate space that changes with the size of the window. How to get it to rescale according to window size and have Y go upwards? The following program should show a dark square in upper right quadrant.

thanks, but i don't know how to accomplish this. should i use getWidth() and getHeight() to make the [-1,+1] interval fit each dimension? and how do i flip? i am not versed with the matrices. is there a method to create a flip transformation? or do i rotate twice? it is essentially specific methods and which arguments to supply that i am looking for.
–
necromancerMay 14 '13 at 2:22

Example added. Thomas you can edit or correct as you see fit. But it shows that your suggestion works. I recommend only transforming copies of the Graphics object to prevent side effects down stream. I also like overriding getPreferredSize(...) as a cleaner way to set my component's and thus my GUI's size. 1+ to the answer.
–
Hovercraft Full Of EelsMay 14 '13 at 2:40