Repositioning components based on mouse position

Hello, I am implementing a zoom feature for a JPanel that is populated with many smaller JPanels.

The premise is: when the user spins the mouse scroll wheel the "zoomPercent" is increased/decreased and then all the child components are resized based on their "defaultSize" and the new "zoomPercent" value. This all works fine. Now the problem I've run into is how to get the child components to relocate towards the mouse pointer based on the "zoomPercent" to give the illusion of zooming. I believe the Trig involved requires the use of the AAA Similar Triangle Theorem but I can't quite figure it out. What I have right now \/ is giving me odd results. When I scroll the mouse wheel forward the elements seem to move towards the mouse pointer, but they don't move away from the pointer when I scroll backwards on the scroll wheel. Eventually, after scrolling forwards and backwards a few times the child components will all be perfectly overlapped and jump to the mouse pointer's position when I try scrolling. Any guidance?

Code:

`private int zoomPercent = 100;`

public void mouseWheelMoved(MouseWheelEvent e)

{

int oldZoomPercent = Math.max(1, zoomPercent);

int notches = -e.getWheelRotation();

int increment = 50;

zoomPercent += increment * notches;

zoomPercent = Math.max(0, zoomPercent);

//mouse position

int x = e.getX();

int y = e.getY();

for (Node node: nodes)

{

int newWidth = node.defaultWidth * zoomPercent / 100;

int newHeight = node.defaultHeight * zoomPercent / 100;

node.setSize(newWidth, newHeight);

int nodeX = node.getLocation().x;

int nodeY = node.getLocation().y;

int dx = Math.abs(x - nodeX);

int dy = Math.abs(y - nodeY);

//distance between component and mouse pointer

double hyp = Math.sqrt(dx * dx + dy * dy);

//angle of hypotenuse

double angle = Math.asin(dy / hyp);

//new hypotenuse length

double newHyp = hyp * zoomPercent / oldZoomPercent;

//horizontal component of hypotenuse

double sin = Math.sin(angle);

//vertical component of hypotenuse

double cos = Math.cos(angle);

//change in horizontal component

dx = (int) Math.abs(sin * newHyp - sin * hyp);

//change in vertical component

dy = (int) Math.abs(cos * newHyp - cos * hyp);

int finalX, finalY = 0;

if (nodeX > x) {

finalX = x + dx;

} else {

finalX = x - dx;

}

if (nodeY > y) {

finalY = y + dy;

} else {

finalY = y - dy;

}

node.setLocation(finalX, finalY);

}

validate();

}