I had a question earlier regarding how I can add panesfrom to a VBox in JavaFX FXML. My question now is how can I edit the things inside the pane I Added? the code for FXML files is still the same. the new edited Java Code is as Follows:
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class HotelReservationController implements Initializable{
@FXML
private ScrollPane scrollPaneContent;
@FXML
private VBox vboxData;
@FXML
private AnchorPane cardAnchor;
@FXML
private HBox cardHBox;
@FXML
private Text cardTitle;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
URL cardURL = getClass().getResource("/application/Cards.fxml");
// vboxData.getChildren().add(cardAnchor);
for (int j = 0; j < 10; j++) {
Parent cardAnchor=null;
Parent cardHBox=null;
Parent cardTitle=null;
try {
cardAnchor = FXMLLoader.load(cardURL);
cardHBox= FXMLLoader.load(cardURL);
cardTitle = FXMLLoader.load(cardURL);
cardTitle.setText("test" + j);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
vboxData.getChildren().add(cardAnchor);
}
try {
connectToHotel();
} catch (ClassNotFoundException | SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
However, when i did this i had the following error:
javafx.fxml.LoadException:
/C:/Users///////bin/application/HotelReservation.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: javafx.scene.layout.AnchorPane cannot be cast to javafx.scene.text.Text
at application.HotelReservationController.initialize(HotelReservationController.java:55)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
How can I add this text field and other text fields (and I guess handling the image pane and the button would be similar to handling them)?