Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite JavaFX coordinate system pane

I need to write a custom pane that behaves like an infinite two-dimensional cartesian coordinate system. When first showing I want 0,0 to be in the center of the pane. The user should be able to navigate the pane by holding down the left mouse button and dragging. It needs to have the ability to zoom in and out. I also have to be able to place nodes at specific coordinates.

Of course I am aware that this is a very specific control and I am not asking anyone to give me step-by-step instructions or write it for me.

I am just new to the world of JFX custom controls and don't know how to approach this problem, especially the whole infinity thing.

like image 678
DeLoreanDriver Avatar asked Jan 29 '23 03:01

DeLoreanDriver


1 Answers

This is not so difficult to achieve as you may think. Just start with a simple Pane. That already gives you the infinte coordinate system. The only difference from your requirement is that the point 0/0 is in the upper left corner and not in the middle. This can be fixed by applying a translate transform to the pane. Zooming and panning can then be achieved in a similar way by adding the corresponding mouse listeners to the Pane.

like image 56
mipa Avatar answered Feb 02 '23 12:02

mipa