Results 1 to 4 of 4
  1. #1
    IveGotAPocket is offline Member
    Join Date
    Dec 2016
    Posts
    2
    Rep Power
    0

    Default fx:define with scenebuilder 2.0

    Trying to use an arraylist with fx:define with Scene Builder 2.0 does not work.

    My goal is to make an array of buttons, which i cannot do in Scene Builder and must make in java code but without being able to use fx:define I cant figure out a way to do this.

    Any help with how I should be making an array of buttons with Scene Builder 2.0 using the setup of main class, controller class, fxml file.

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: fx:define with scenebuilder 2.0

    So, you want to add Button nodes into an array, but you do not want to program this via Java in the Controller class and you do not want to hardcode it in the fxml file because Scenebuilder does not like that. Am i understanding this correctly?

    There are newer versions of Scenebuilder available, but unfortunately they do not support fx:define either. You might have to go the Controller class route.
    Last edited by benji2505; 12-13-2016 at 01:42 AM.

  3. #3
    IveGotAPocket is offline Member
    Join Date
    Dec 2016
    Posts
    2
    Rep Power
    0

    Default Re: fx:define with scenebuilder 2.0

    To clarify, what I was trying to do was group objects into an array list in the FXML file so that I could just have @FXML private List<Objects> instead of have to declare every object individually in my controller class.

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: fx:define with scenebuilder 2.0

    If you have a set of Buttons defined in the fxml file and you want to add these Buttons into an array there is no functionality in Scenebuilder for this that I am aware of.

    As you mentioned before there are 2 options:

    1. create the array in the fxml file via fx:define. This should be the option that you are looking for. In the controller class you will only need the reference to the collection, not the references to the Buttons themselves.

    2. create the array in the controller class; you will need references to the buttons and an instance of a collection that takes Buttons. Typically you would find the addition into the array in an initialize method().

    option 1. should look something like:

    Java FX Code:
    <fx:define>
        <ArrayList fx:id="btnList">
            <fx:reference source="btn1" />
            <fx:reference source="btn2" /> 
        </ArrayList>
    </fx:define>
    Then you just add the reference
    @FXML
    private List<Button> btnList;

    and you should be able to use btnList without any further references to the Button nodes themselves.
    Last edited by benji2505; 12-13-2016 at 02:00 PM.

Similar Threads

  1. define open
    By Crowdy199 in forum New To Java
    Replies: 6
    Last Post: 06-09-2012, 03:28 PM
  2. how do you actually define a method?
    By edelric666 in forum New To Java
    Replies: 3
    Last Post: 10-30-2010, 10:26 PM
  3. Define class and constructors
    By HaDesT in forum New To Java
    Replies: 2
    Last Post: 03-04-2010, 05:02 PM
  4. define a variable
    By jperson in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 02:33 AM
  5. Define this error.
    By jaicea in forum New To Java
    Replies: 3
    Last Post: 12-02-2009, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •