Relative Positioning of a Point

B

B. Clay

I'd like to be able to place a point (g.fillOval) in a relative
position in a pane, rather than an absolute one. Is there a good way
to do this?

For example, if the pane is 100x100, and I put the point at 10,10, if
the user resizes such that the pane ends up as 200x200, I want the
point to be at 20,20.

Thanks.

P.S. - I've been unable to access the java website tutorials and API
for a few days. Anyone else having this problem?
 
N

nos

B. Clay said:
I'd like to be able to place a point (g.fillOval) in a relative
position in a pane, rather than an absolute one. Is there a good way
to do this?

For example, if the pane is 100x100, and I put the point at 10,10, if
the user resizes such that the pane ends up as 200x200, I want the
point to be at 20,20.

Thanks.

P.S. - I've been unable to access the java website tutorials and API
for a few days. Anyone else having this problem?

In addition to resize, the window can be moved. When the window is
resized, the following method will be called if you set up a listener (that
is your job to figure out how to do the listener.) This method will find
out where the window is, and how big it is, then call another method
to handle it.

public void componentResized(ComponentEvent e)
{
Component c = e.getComponent();
int w = c.getSize().width;
int h = c.getSize().height;
int x = c.getX();
int y = c.getY();
HandleWindowResize(x, y, h, w);
}
 
T

Thomas Weidenfeller

B. Clay said:
I'd like to be able to place a point (g.fillOval) in a relative
position in a pane, rather than an absolute one. Is there a good way
to do this?

For example, if the pane is 100x100, and I put the point at 10,10, if
the user resizes such that the pane ends up as 200x200, I want the
point to be at 20,20.

See AffineTransform and the long explanation about coordinate spaces in
the API documentation of Graphics or Graphics2D (I forgot which one).

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top