You can use the StackPane
class to solve your problem. Have a look at the following code:
GridPane g1 = new GridPane();
StackPane sp = new StackPane();
Rectangle r = new Rectangle(100, 100);
r.setFill(Color.AQUA);
Text t = new Text("StackOverFlow");
sp.getChildren().addAll(r,t);
g1.add(sp, 0, 0);
Scene sc = new Scene(g1,200,200);
primaryStage.setScene(sc);
primaryStage.show();
The stackpane works in the "last in -- first out" way. So your last added child is the first to display (or better: the element on top of the pane). Any following children will be placed behind the first child.
To solve your problem, create a stackpane, then put the rectangle in it, and then the text. After that, put the stackpane in the desired position on the gridpane.