3 Replies Latest reply on Nov 26, 2012 7:26 AM by MiPa

    How to clone a scene node like GridPane?

      HI All,
      I have a Scene Graph with several containers of node objects.
      One of them is a ScrollPane which contains GridPanes.
      I am able to use SceneBuilder to create one Gridpane, and now trying to create the other GridPanes (1..n where n is dynamic) to show my data.
      It seems to me that I have to do it in FX ontroller code as I don't know how to do this in ScendBuilder, or FXML
      I was thinking about using the exiting GridPane (the first one) and try new GridPane(), and clone them one at a time.
      Can somebody give me a hand to help create and clone these GridPane objects?
      Actual code, or pseudo code will be very nice.
      Thanks in advance, and happy Thanksgiving.
        • 1. Re: How to clone a scene node like GridPane?
          You can't clone any Node because they are not cloneable. Being able to do that would probably also be very error prone due to various restrictions on nodes. You will have to create them in code but one by one. Just write a little helper function to do that.

          You might also define a template node in FXML via SceneBuilder and load that several times but I am not sure whether this makes sense because you would still have to adjust ids and such things.
          • 2. Re: How to clone a scene node like GridPane?
            hi MiPa,
            Thanks for your input.
            having the cloneable capability is important to me, and I believe there are ways to clone a node, afterall it is just another "complicated" object.
            the choice to clone and work out as a class extension is what I am after and I have not explore using template node in FXML.
            I personally have preference is java programming side rather than programming on FXML side.
            Just thought to ask the community if there is an "easy" or a clever way to clone a node.
            Earlier FX version has duplicate function but not available anymore...
            • 3. Re: How to clone a scene node like GridPane?
              Have you tried the Builders? I think one can call the build method several times but I have never tried that myself.