javafxjavafx-2javafx-8snap-to-grid

Grid functionality - Gridpane or custom?


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.


Solution

  • 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.