This discussion is archived
5 Replies Latest reply: Nov 25, 2012 1:35 PM by 960968 RSS

Generate multiple GridPanes using SceneBuilder

960968 Newbie
Currently Being Moderated
HI All,
I am new to javaFX, and very happy with SceneBuilder to create a TabPane content which includes a GridPane which I use it to display contents of record from a search, such as name, address, phone number etc. My TabPane content also has other componets such as standalone text, VBox with some other componets inside. My current setup works perfectly and the GridPane will show all the componet fields and values within its structure.

My question is my search routine will return mutiple (dynamic such as 1 to n) records, which I need to show them all in sequence preferrably using the same GridPane arrangement as I discussed earlier.

I struggled with understanding the FXML file and its controller trying to extend the FXML file ScendBuilder generated, and unable to generate additional Grandpanes, and show them in sequence (which I think can increment the SetlayoutY() value).

Can somebody shed some light to help me solve my problem? using the FXML from SceneBuilder is certainly preferred as I also invested time with other TabPanes. But I am also comfortable to re-do my GUI in code instead of using ScenBuilder.

Thanks in advance.

Ron
  • 1. Re: Generate multiple GridPanes using SceneBuilder
    bouye Journeyer
    Currently Being Moderated
    My guess is that you are trying to do something similar to:
    VBox personVBox = VBoxBuilder.create().build()
    for (Person person : queryResult) {
      GridPane personPane = (GridPane)fxmlLoader.load();
      PersonPaneController controller = (personNode)fxmlLoader.getController();
      controller.setPerson(person);
      personVBox.getChildren().add(personPane);
    }
    ScrollPane personTabContent = ScrollPaneBuilder.create().node(personVBox).build();
    personTab.setContent(personTabContent);
    Where for each person, you get a new copy of your FXML node and populate it and then display the whole in the tab.
    If your TabPane is in its own FXML, this code would need to go in the appropriate controller for that FXML. Of course when there is only 1 result, no need to create a VBox or a ScrollPane!

    Note : I am not sure that you can reuse the same fxmlLoader to get different controller/node though (to be true, I haven't tried that yet), so you may end up reinitializing the fxmLoader in each loop in the end.

    Edited by: bouye on Nov 13, 2012 12:46 PM
  • 2. Re: Generate multiple GridPanes using SceneBuilder
    960968 Newbie
    Currently Being Moderated
    bouye,
    Thanks so much for your reply. In a way, I think you answered many aspects of my question.
    Indeed your Vbox approach is similiar to my GridPane, and your pseudo code appears to be a good approach.
    Do you mind send me some references to some actual code/script where I can play with the code to see how they actually work.
    For my work, I am using just one giant FXML file and is struggling through to break them up to separate FXML files with their respective controllers.
    It seems to me that the fields and variables in a FXML and controller set are private, and I need to pass values between different FXML/Controller sets.
    Positioning mutiple nodes within GridPane or Vbox as you described is also a challenge for me for now.
    If you have some working samples or references to demostrate your approach where I can step through, this will be very helpful to have a better understanding to work with JavaFX, FXML, SceneBuilder and integration in between.
    Again thanks for your help.
    Ron
  • 3. Re: Generate multiple GridPanes using SceneBuilder
    bouye Journeyer
    Currently Being Moderated
    Sorry but I do not have any ready-to-use project (even small one) currently readily and publically accessible that may demonstrate this.

    There are a couple of pointers I can give you though:

    1) You can include FXML into FXML either by hand or using SceneBuilder!
    This way you can separate you very big FXML into smaller much more manageable chunks.
    ie: the content of each tab can be set into it's very own FXML. Which makes it easier when modifying the content of a pane without dealing with the very big design that is not easy to edit.

    2) When including an external FXML you can give it a fx:id like any other control.
    If you do that (idOfExternalFXML) and if that FXML has its own control (ZeControllerForExternalFXML) then in you main controller you can have :
    @FXML
    private GridPane idOfExternalFXML;
    
    @FXML
    private ZeControllerForExternalFXML idOfExternalFXMLController;
    That's right! Starting FX 2.2 (or was it 2.1?) you get a free reference to the controller of an included FXML just by adding "Controller" ad the end of the id.
    No need to do that by hand anymore!

    3) You're not forced to declare anything private into your controller, they can be declared package protected, public or whatever you want.
    This means that you could have in the included FXML's controller:
    @FXML
    Label nameLabel;
    and in the main controller:
    idOfExternalFXMLController.nameLabel.setText(...);
    I prefer not to do that, but you can, nothing prevents you from doing it.

    4) and of course, for content that needs to be duplicated (like the personPane in my previous message), you have to create a separate, non-included FXML + controller and then populate the main FXML with it at runtime.
  • 4. Re: Generate multiple GridPanes using SceneBuilder
    960968 Newbie
    Currently Being Moderated
    Hi Bouye,
    Really thanks for your comment, as I continue to research this issue and came across the Login sample which demonstrate the subtle realtionship between FXML and its controller. It has an interesting design which extends Anchored Pane and relates its corresponding FXML as content in the login example. I just need to spend more time to go into detail into this example and learn from it.
    I really wished there is some sort of formal writing like a tutorial, or text book to talk about applying JavaFX, FXML, Scenebuilder in a more meaningful manner where developers out there can learn and apply. For what you have discussed here, it is complicated enough for me to re-think whether I need to re-do my user interface all in FX code, instead of some in SceneBuilder, and in my situation now, digging for information to integrate it with the main program, and dealing with deifferent controllers. the challenging problem is the lack of relevant technical information, and no logical examples and relevant explaination. Just looking at the API does not help me. What is your thought on that re-doing it all in Fx code instead of mixing it with SceneBuilder?
    javaFx web site only suggest 2 books which I have already. The tutorials are written by tech writers which provides very generic functional descrption. I am not aware of any formal refernce to the topics we discussed here. Did I miss something obvious? You probably have much deeper knowledge than many of us. Can you point us to the relevant sources?
    Thanks again.
    Ron
  • 5. Re: Generate multiple GridPanes using SceneBuilder
    960968 Newbie
    Currently Being Moderated
    I ended up doint it all in FX and bypassing SceneBuilder. I would concur that SceneBuilder will be a great tool for prototype and UI modeling.
    Thanks,
    Ron

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points