Reputation: 3538
I have a JScrollPanel implemented correctly . I want to be able to draw a graph in the scrolloable area . The JScrollPanel i produced has its origin (x=0,y=0) in the top left corner .
How can i change this so that the origin becomes bottom left corner of the JScrollPane ?In other words the co-ordinate values should increase up and to the right.
I need this because this origin style corresponds to the LANDSCAPE mode in which i want the graph to be visualized . I went through the JComponent doucmentation . I am not sure which API to use .
Upvotes: 2
Views: 97
Reputation: 1648
You are not able to change to coordinates of where the origin of the JScrollPane is located. In all of swing the origin is defined as top left. What you have to do is manually correct the y values.
This is as simple as int outputY = JScrollPanelObject.getHeight() - inputY;
This flips the Y values making it appear as if it is increasing up and to the right.
EDIT:
In that case you can grab a Graphics2D
object just call rotate on it.
in most cases the Graphics
object handed down from the paint method can be casted to a Graphics2D
.
I do believe you want to rotate it -90 degrees or -Math.PI/2
Upvotes: 4