0

I wish to create a grid where you can place elements on who will snap to grid.

The grid would consist of 25x25 px cells and could potentially be 1000x1000 cells large. I would have to be able to individually access all cells and be able to turn off the snap-to-grid and some other functionalities.

As this is in JavaFX there is a layout component called GridPane. My question is, should I create my own system that will then suffice to all my needs or should I use the existing GridPane layout?

I am currently thinking of creating my own system as I fear GridPane will not provide all the functionality I want.

Limnic
  • 1,826
  • 1
  • 20
  • 45
  • I think your elements will span multiple cells, will not they? Spanning with snapping may arise problems, so it is preferable to implement your custom grid. – Uluk Biy May 28 '15 at 09:23
  • Indeed it will. Thanks for your recommendations. I am assuming a Canvas would be best for complete control? – Limnic May 28 '15 at 09:30
  • 1
    If the user will interact with elements, like selecting clicking dragging etc, then it will be difficult to do that with canvas. – Uluk Biy May 28 '15 at 12:21
  • 1
    Since grid is for visual purposes only, you can simply use one canvas as a background with the lines drawn as a grid. Because the snapping functionality will be implemented by you, you will calculate the nearest grid lines and position the element accordingly. I mean these grid lines are always there even if they didn't drawn. – Uluk Biy May 28 '15 at 12:25

1 Answers1

1

If your cells are going to be a fixed size, try using a TilePane instead. GridPane is made for grids where rows and columns can have independent sizes and cells can span multiple rows and/or columns.

However, since you mentioned a size of 1000x1000, you will probably have a lot better performance if you create a custom solution yourself. You should also keep in mind that if you're going to use 1000x1000 nodes, your scene graph will get extremely large and performance will suffer. If the nodes you're using are simple enough to draw on a Canvas, you will get a lot better performance that way.

Steven Van Impe
  • 1,153
  • 8
  • 15