1

I try to add a borderpane in my gridpane with the method add() like that :

GridPane grid = new GridPane();
grid.getChildren().add(new BorderPane());
grid.getChildren().add(new BorderPane(), 1, 0); // ERROR HERE

But I receive this error :

error: no suitable method found for add(BorderPane,int,int) grid.getChildren().add(new BorderPane(), 1, 0); method Collection.add(Node) is not applicable (actual and formal argument lists differ in length) method List.add(Node) is not applicable (actual and formal argument lists differ in length) method List.add(int,Node) is not applicable (actual and formal argument lists differ in length) Note: C:\Users\OFN\Documents\NetBeansProjects\CryptionTest\src\fr\cryption\control\ExplorerPage.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

I searched for three hours on Google and Stackoverflow but there is no solution for my problem.

Here is the imports I used :

import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;

Do you have an idea ?

Thanks.

mtnp
  • 314
  • 7
  • 24
  • To help people give you an aswer, I believe you should post the error you get and a minimum working example. – Nerva Jan 18 '18 at 22:08
  • 2
    `ObservableList` doesn't have an `add(Node, int, int)` method (or any method that accepts parameters that can be automatically case from that). Perhaps you mean `grid.add(...)`? – James_D Jan 18 '18 at 22:22
  • I edited the post with the message sorry. – mtnp Jan 18 '18 at 22:27
  • Damn, James_D you find the solution !! I deleted the getChildren() and it works ! What a noob I am.. Thank you, but i'm a little surprised that getChildren() is not allowed. – mtnp Jan 18 '18 at 22:28
  • 1
    @OFFEN: Why are you surprised? `getChildren()` is defined in `Pane` which does not use any layout parameters. Row/column index only makes sense for a layout like `GridPane`. It wouldn't make any sense for e.g. `FlowPane`. Those `add` methods of `GridPane` are only convenience methods for assigning the layout parameters and adding the child using a single method call. You could add the children to the list yourself but in that case you need to set the layout parameters yourself: `GridPane.setRowIndex(c, 1); GridPane.setColumnIndex(c, 2); grid.getChildren().add(c);` – fabian Jan 18 '18 at 22:47
  • @fabian I saw this method in an example of a tutorial and I thought it could work with all containers (get child of Gridpane doesn't shock me). Moreover, it works without parameters so it was disturbing. But I keep in mind your message I need to train a lot again. Thanks. – mtnp Jan 18 '18 at 22:57
  • `getChildren()` returns an `ObservableList`, so its add method is defined by `List` interface. `Gridpane` defined its own add method, and internally it calls the add method of the list. There is nothing confusing here. – Jai Jan 19 '18 at 02:18

0 Answers0