Order of the elements in the Anchor Pane












0















when I try to initialize the Anchor Pane a strange things happens: if I put the elements in this order I cannot click with the mouse, for example, on the elements of the list.



AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load());


But if I write it on this way I'm able to select the items on the list but not the items in the menubar:



AnchorPane root = new AnchorPane(fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load(), listLoader.load());


Do you know How should I write the elements to make at least the button, the menu and the list clickable?



This is the full code:



@Override
public void start(Stage stage) throws Exception {
FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));
FXMLLoader buttonLoader = new FXMLLoader(getClass().getResource("button.fxml"));

AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(), menuLoader.load());

ListController listController = listLoader.getController();
TextAreaController textareaController = textareaLoader.getController();
TextFieldController fieldController = fieldLoader.getController();
MenuBarController menuController = menuLoader.getController();
ButtonController buttonController = buttonLoader.getController();

DataModel model = new DataModel();
listController.initModel(model);
textareaController.initModel(model);
fieldController.initModel(model);
menuController.initModel(model);
buttonController.initModel(model);

Scene scene = new Scene(root, 603, 403);
stage.setScene(scene);
stage.show();
}


Lista.fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">







Button.fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ButtonController">










MenuBar.fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
<children>
<MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
<menus>
<Menu text="File">
<items>
<MenuItem onAction="#elimina" text="Elimina" />
</items>
</Menu>
<Menu text="Cambia Account">
<items>
<MenuItem fx:id="email1" text="filippo@hotmail.it" />
<MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
<MenuItem fx:id="email3" text="alessandro@gmail.it" />
</items>
</Menu>
</menus>
</MenuBar>
</children>




Textarea.fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">







Textfield.fxml:



<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mouseTransparent="false" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.TextFieldController">
















EDIT:
So should I declare more than one Anchor Pane and attach them to a main Anchor Pane?



    AnchorPane root = new AnchorPane();

AnchorPane lista = new AnchorPane(listLoader.load());
AnchorPane textarea = new AnchorPane(textareaLoader.load());
AnchorPane field = new AnchorPane(fieldLoader.load());
AnchorPane menu = new AnchorPane(menuLoader.load());
AnchorPane button = new AnchorPane(buttonLoader.load());

root.getChildren().addAll(lista, textarea, field, menu, button);


EDIT2: This is the output of my program, can I create it with a BorderPane? Because It automatically anchor the elements on the right, left ecc... and for example I cannot put the textfield as you can see in the image
Output










share|improve this question





























    0















    when I try to initialize the Anchor Pane a strange things happens: if I put the elements in this order I cannot click with the mouse, for example, on the elements of the list.



    AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load());


    But if I write it on this way I'm able to select the items on the list but not the items in the menubar:



    AnchorPane root = new AnchorPane(fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load(), listLoader.load());


    Do you know How should I write the elements to make at least the button, the menu and the list clickable?



    This is the full code:



    @Override
    public void start(Stage stage) throws Exception {
    FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
    FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
    FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
    FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));
    FXMLLoader buttonLoader = new FXMLLoader(getClass().getResource("button.fxml"));

    AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(), menuLoader.load());

    ListController listController = listLoader.getController();
    TextAreaController textareaController = textareaLoader.getController();
    TextFieldController fieldController = fieldLoader.getController();
    MenuBarController menuController = menuLoader.getController();
    ButtonController buttonController = buttonLoader.getController();

    DataModel model = new DataModel();
    listController.initModel(model);
    textareaController.initModel(model);
    fieldController.initModel(model);
    menuController.initModel(model);
    buttonController.initModel(model);

    Scene scene = new Scene(root, 603, 403);
    stage.setScene(scene);
    stage.show();
    }


    Lista.fxml:



    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">







    Button.fxml:



    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ButtonController">










    MenuBar.fxml:



    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
    <children>
    <MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
    <menus>
    <Menu text="File">
    <items>
    <MenuItem onAction="#elimina" text="Elimina" />
    </items>
    </Menu>
    <Menu text="Cambia Account">
    <items>
    <MenuItem fx:id="email1" text="filippo@hotmail.it" />
    <MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
    <MenuItem fx:id="email3" text="alessandro@gmail.it" />
    </items>
    </Menu>
    </menus>
    </MenuBar>
    </children>




    Textarea.fxml:



    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">







    Textfield.fxml:



    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mouseTransparent="false" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.TextFieldController">
















    EDIT:
    So should I declare more than one Anchor Pane and attach them to a main Anchor Pane?



        AnchorPane root = new AnchorPane();

    AnchorPane lista = new AnchorPane(listLoader.load());
    AnchorPane textarea = new AnchorPane(textareaLoader.load());
    AnchorPane field = new AnchorPane(fieldLoader.load());
    AnchorPane menu = new AnchorPane(menuLoader.load());
    AnchorPane button = new AnchorPane(buttonLoader.load());

    root.getChildren().addAll(lista, textarea, field, menu, button);


    EDIT2: This is the output of my program, can I create it with a BorderPane? Because It automatically anchor the elements on the right, left ecc... and for example I cannot put the textfield as you can see in the image
    Output










    share|improve this question



























      0












      0








      0








      when I try to initialize the Anchor Pane a strange things happens: if I put the elements in this order I cannot click with the mouse, for example, on the elements of the list.



      AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load());


      But if I write it on this way I'm able to select the items on the list but not the items in the menubar:



      AnchorPane root = new AnchorPane(fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load(), listLoader.load());


      Do you know How should I write the elements to make at least the button, the menu and the list clickable?



      This is the full code:



      @Override
      public void start(Stage stage) throws Exception {
      FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
      FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
      FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
      FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));
      FXMLLoader buttonLoader = new FXMLLoader(getClass().getResource("button.fxml"));

      AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(), menuLoader.load());

      ListController listController = listLoader.getController();
      TextAreaController textareaController = textareaLoader.getController();
      TextFieldController fieldController = fieldLoader.getController();
      MenuBarController menuController = menuLoader.getController();
      ButtonController buttonController = buttonLoader.getController();

      DataModel model = new DataModel();
      listController.initModel(model);
      textareaController.initModel(model);
      fieldController.initModel(model);
      menuController.initModel(model);
      buttonController.initModel(model);

      Scene scene = new Scene(root, 603, 403);
      stage.setScene(scene);
      stage.show();
      }


      Lista.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">







      Button.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ButtonController">










      MenuBar.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
      <children>
      <MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
      <menus>
      <Menu text="File">
      <items>
      <MenuItem onAction="#elimina" text="Elimina" />
      </items>
      </Menu>
      <Menu text="Cambia Account">
      <items>
      <MenuItem fx:id="email1" text="filippo@hotmail.it" />
      <MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
      <MenuItem fx:id="email3" text="alessandro@gmail.it" />
      </items>
      </Menu>
      </menus>
      </MenuBar>
      </children>




      Textarea.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">







      Textfield.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mouseTransparent="false" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.TextFieldController">
















      EDIT:
      So should I declare more than one Anchor Pane and attach them to a main Anchor Pane?



          AnchorPane root = new AnchorPane();

      AnchorPane lista = new AnchorPane(listLoader.load());
      AnchorPane textarea = new AnchorPane(textareaLoader.load());
      AnchorPane field = new AnchorPane(fieldLoader.load());
      AnchorPane menu = new AnchorPane(menuLoader.load());
      AnchorPane button = new AnchorPane(buttonLoader.load());

      root.getChildren().addAll(lista, textarea, field, menu, button);


      EDIT2: This is the output of my program, can I create it with a BorderPane? Because It automatically anchor the elements on the right, left ecc... and for example I cannot put the textfield as you can see in the image
      Output










      share|improve this question
















      when I try to initialize the Anchor Pane a strange things happens: if I put the elements in this order I cannot click with the mouse, for example, on the elements of the list.



      AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load());


      But if I write it on this way I'm able to select the items on the list but not the items in the menubar:



      AnchorPane root = new AnchorPane(fieldLoader.load(), textareaLoader.load(), buttonLoader.load(),  menuLoader.load(), listLoader.load());


      Do you know How should I write the elements to make at least the button, the menu and the list clickable?



      This is the full code:



      @Override
      public void start(Stage stage) throws Exception {
      FXMLLoader listLoader = new FXMLLoader(getClass().getResource("lista.fxml"));
      FXMLLoader textareaLoader = new FXMLLoader(getClass().getResource("textarea.fxml"));
      FXMLLoader fieldLoader = new FXMLLoader(getClass().getResource("textfield.fxml"));
      FXMLLoader menuLoader = new FXMLLoader(getClass().getResource("menubar.fxml"));
      FXMLLoader buttonLoader = new FXMLLoader(getClass().getResource("button.fxml"));

      AnchorPane root = new AnchorPane(listLoader.load(), fieldLoader.load(), textareaLoader.load(), buttonLoader.load(), menuLoader.load());

      ListController listController = listLoader.getController();
      TextAreaController textareaController = textareaLoader.getController();
      TextFieldController fieldController = fieldLoader.getController();
      MenuBarController menuController = menuLoader.getController();
      ButtonController buttonController = buttonLoader.getController();

      DataModel model = new DataModel();
      listController.initModel(model);
      textareaController.initModel(model);
      fieldController.initModel(model);
      menuController.initModel(model);
      buttonController.initModel(model);

      Scene scene = new Scene(root, 603, 403);
      stage.setScene(scene);
      stage.show();
      }


      Lista.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">







      Button.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ButtonController">










      MenuBar.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
      <children>
      <MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
      <menus>
      <Menu text="File">
      <items>
      <MenuItem onAction="#elimina" text="Elimina" />
      </items>
      </Menu>
      <Menu text="Cambia Account">
      <items>
      <MenuItem fx:id="email1" text="filippo@hotmail.it" />
      <MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
      <MenuItem fx:id="email3" text="alessandro@gmail.it" />
      </items>
      </Menu>
      </menus>
      </MenuBar>
      </children>




      Textarea.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">







      Textfield.fxml:



      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mouseTransparent="false" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.TextFieldController">
















      EDIT:
      So should I declare more than one Anchor Pane and attach them to a main Anchor Pane?



          AnchorPane root = new AnchorPane();

      AnchorPane lista = new AnchorPane(listLoader.load());
      AnchorPane textarea = new AnchorPane(textareaLoader.load());
      AnchorPane field = new AnchorPane(fieldLoader.load());
      AnchorPane menu = new AnchorPane(menuLoader.load());
      AnchorPane button = new AnchorPane(buttonLoader.load());

      root.getChildren().addAll(lista, textarea, field, menu, button);


      EDIT2: This is the output of my program, can I create it with a BorderPane? Because It automatically anchor the elements on the right, left ecc... and for example I cannot put the textfield as you can see in the image
      Output







      java listview javafx observable menuitem






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 14:31







      Samoa Joe

















      asked Nov 19 '18 at 12:42









      Samoa JoeSamoa Joe

      206




      206
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Probably consecutively loaded panes have the same sizes. After loading them you get a stack of panes with the same sizes. In that case only the top most pane (added as last one) is responsive for mouse events. I would suggest to provide correct sizes and anchors for every pane.
          If my thesis is incorrect please provide more code.



          EDIT: if child1 and child2 had the same sizes only the blue one would be visible but still the red one would be present but underneath and all covered by blue one. It's the same situation with your app. Btw you are misusing AnchorPane. AnchorPane is designated to anchor children.



          import javafx.application.Application;
          import javafx.scene.Scene;
          import javafx.scene.layout.AnchorPane;
          import javafx.stage.Stage;

          public class AnchorPaneTest extends Application {

          public static void main(String args) {
          launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {
          AnchorPane anchorPane = new AnchorPane();

          AnchorPane child1 = new AnchorPane();
          child1.setPrefSize(400., 600.);
          child1.setStyle("-fx-background-color: red;");

          AnchorPane child2 = new AnchorPane();
          child2.setPrefSize(400., 300.);
          child2.setStyle("-fx-background-color: blue;");

          anchorPane.getChildren().addAll(child1, child2);

          stage.setScene(new Scene(anchorPane));
          stage.show();
          }
          }





          share|improve this answer


























          • I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

            – Samoa Joe
            Nov 19 '18 at 13:33











          • I've edited my answer to give you better picture.

            – Przemek Krysztofiak
            Nov 19 '18 at 13:46











          • I've edited the question.

            – Samoa Joe
            Nov 19 '18 at 13:59






          • 1





            Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

            – Przemek Krysztofiak
            Nov 19 '18 at 14:07













          • @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

            – Pagbo
            Nov 19 '18 at 14:11











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374893%2forder-of-the-elements-in-the-anchor-pane%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Probably consecutively loaded panes have the same sizes. After loading them you get a stack of panes with the same sizes. In that case only the top most pane (added as last one) is responsive for mouse events. I would suggest to provide correct sizes and anchors for every pane.
          If my thesis is incorrect please provide more code.



          EDIT: if child1 and child2 had the same sizes only the blue one would be visible but still the red one would be present but underneath and all covered by blue one. It's the same situation with your app. Btw you are misusing AnchorPane. AnchorPane is designated to anchor children.



          import javafx.application.Application;
          import javafx.scene.Scene;
          import javafx.scene.layout.AnchorPane;
          import javafx.stage.Stage;

          public class AnchorPaneTest extends Application {

          public static void main(String args) {
          launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {
          AnchorPane anchorPane = new AnchorPane();

          AnchorPane child1 = new AnchorPane();
          child1.setPrefSize(400., 600.);
          child1.setStyle("-fx-background-color: red;");

          AnchorPane child2 = new AnchorPane();
          child2.setPrefSize(400., 300.);
          child2.setStyle("-fx-background-color: blue;");

          anchorPane.getChildren().addAll(child1, child2);

          stage.setScene(new Scene(anchorPane));
          stage.show();
          }
          }





          share|improve this answer


























          • I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

            – Samoa Joe
            Nov 19 '18 at 13:33











          • I've edited my answer to give you better picture.

            – Przemek Krysztofiak
            Nov 19 '18 at 13:46











          • I've edited the question.

            – Samoa Joe
            Nov 19 '18 at 13:59






          • 1





            Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

            – Przemek Krysztofiak
            Nov 19 '18 at 14:07













          • @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

            – Pagbo
            Nov 19 '18 at 14:11
















          0














          Probably consecutively loaded panes have the same sizes. After loading them you get a stack of panes with the same sizes. In that case only the top most pane (added as last one) is responsive for mouse events. I would suggest to provide correct sizes and anchors for every pane.
          If my thesis is incorrect please provide more code.



          EDIT: if child1 and child2 had the same sizes only the blue one would be visible but still the red one would be present but underneath and all covered by blue one. It's the same situation with your app. Btw you are misusing AnchorPane. AnchorPane is designated to anchor children.



          import javafx.application.Application;
          import javafx.scene.Scene;
          import javafx.scene.layout.AnchorPane;
          import javafx.stage.Stage;

          public class AnchorPaneTest extends Application {

          public static void main(String args) {
          launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {
          AnchorPane anchorPane = new AnchorPane();

          AnchorPane child1 = new AnchorPane();
          child1.setPrefSize(400., 600.);
          child1.setStyle("-fx-background-color: red;");

          AnchorPane child2 = new AnchorPane();
          child2.setPrefSize(400., 300.);
          child2.setStyle("-fx-background-color: blue;");

          anchorPane.getChildren().addAll(child1, child2);

          stage.setScene(new Scene(anchorPane));
          stage.show();
          }
          }





          share|improve this answer


























          • I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

            – Samoa Joe
            Nov 19 '18 at 13:33











          • I've edited my answer to give you better picture.

            – Przemek Krysztofiak
            Nov 19 '18 at 13:46











          • I've edited the question.

            – Samoa Joe
            Nov 19 '18 at 13:59






          • 1





            Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

            – Przemek Krysztofiak
            Nov 19 '18 at 14:07













          • @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

            – Pagbo
            Nov 19 '18 at 14:11














          0












          0








          0







          Probably consecutively loaded panes have the same sizes. After loading them you get a stack of panes with the same sizes. In that case only the top most pane (added as last one) is responsive for mouse events. I would suggest to provide correct sizes and anchors for every pane.
          If my thesis is incorrect please provide more code.



          EDIT: if child1 and child2 had the same sizes only the blue one would be visible but still the red one would be present but underneath and all covered by blue one. It's the same situation with your app. Btw you are misusing AnchorPane. AnchorPane is designated to anchor children.



          import javafx.application.Application;
          import javafx.scene.Scene;
          import javafx.scene.layout.AnchorPane;
          import javafx.stage.Stage;

          public class AnchorPaneTest extends Application {

          public static void main(String args) {
          launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {
          AnchorPane anchorPane = new AnchorPane();

          AnchorPane child1 = new AnchorPane();
          child1.setPrefSize(400., 600.);
          child1.setStyle("-fx-background-color: red;");

          AnchorPane child2 = new AnchorPane();
          child2.setPrefSize(400., 300.);
          child2.setStyle("-fx-background-color: blue;");

          anchorPane.getChildren().addAll(child1, child2);

          stage.setScene(new Scene(anchorPane));
          stage.show();
          }
          }





          share|improve this answer















          Probably consecutively loaded panes have the same sizes. After loading them you get a stack of panes with the same sizes. In that case only the top most pane (added as last one) is responsive for mouse events. I would suggest to provide correct sizes and anchors for every pane.
          If my thesis is incorrect please provide more code.



          EDIT: if child1 and child2 had the same sizes only the blue one would be visible but still the red one would be present but underneath and all covered by blue one. It's the same situation with your app. Btw you are misusing AnchorPane. AnchorPane is designated to anchor children.



          import javafx.application.Application;
          import javafx.scene.Scene;
          import javafx.scene.layout.AnchorPane;
          import javafx.stage.Stage;

          public class AnchorPaneTest extends Application {

          public static void main(String args) {
          launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {
          AnchorPane anchorPane = new AnchorPane();

          AnchorPane child1 = new AnchorPane();
          child1.setPrefSize(400., 600.);
          child1.setStyle("-fx-background-color: red;");

          AnchorPane child2 = new AnchorPane();
          child2.setPrefSize(400., 300.);
          child2.setStyle("-fx-background-color: blue;");

          anchorPane.getChildren().addAll(child1, child2);

          stage.setScene(new Scene(anchorPane));
          stage.show();
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 13:45

























          answered Nov 19 '18 at 13:16









          Przemek KrysztofiakPrzemek Krysztofiak

          2067




          2067













          • I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

            – Samoa Joe
            Nov 19 '18 at 13:33











          • I've edited my answer to give you better picture.

            – Przemek Krysztofiak
            Nov 19 '18 at 13:46











          • I've edited the question.

            – Samoa Joe
            Nov 19 '18 at 13:59






          • 1





            Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

            – Przemek Krysztofiak
            Nov 19 '18 at 14:07













          • @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

            – Pagbo
            Nov 19 '18 at 14:11



















          • I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

            – Samoa Joe
            Nov 19 '18 at 13:33











          • I've edited my answer to give you better picture.

            – Przemek Krysztofiak
            Nov 19 '18 at 13:46











          • I've edited the question.

            – Samoa Joe
            Nov 19 '18 at 13:59






          • 1





            Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

            – Przemek Krysztofiak
            Nov 19 '18 at 14:07













          • @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

            – Pagbo
            Nov 19 '18 at 14:11

















          I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

          – Samoa Joe
          Nov 19 '18 at 13:33





          I added all the fxml files. I made the design with Scene Builder and when I execute the code the output is as I desire, with none of the objects is anchored on another one.

          – Samoa Joe
          Nov 19 '18 at 13:33













          I've edited my answer to give you better picture.

          – Przemek Krysztofiak
          Nov 19 '18 at 13:46





          I've edited my answer to give you better picture.

          – Przemek Krysztofiak
          Nov 19 '18 at 13:46













          I've edited the question.

          – Samoa Joe
          Nov 19 '18 at 13:59





          I've edited the question.

          – Samoa Joe
          Nov 19 '18 at 13:59




          1




          1





          Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

          – Przemek Krysztofiak
          Nov 19 '18 at 14:07







          Remove 'maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"' from all fxmls you listed and run the app. This will give you a clue what your are doing wrong. Next try to use BorderPane instead of your main AnchorPane (make a desing in scene builder). Use methods BorderPane.setLeft(), setRigth(), setCenter(), etc...

          – Przemek Krysztofiak
          Nov 19 '18 at 14:07















          @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

          – Pagbo
          Nov 19 '18 at 14:11





          @SamoaJoe I will add you should spend a few time to understand the goal of the differents layout. AnchorPane could be useful in some specific cases, but I don't see anything in your code that justify this choice.

          – Pagbo
          Nov 19 '18 at 14:11


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374893%2forder-of-the-elements-in-the-anchor-pane%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word