2

I am trying to create a JavaFX application for file encryption I am fairly new to JavaFX so I am still learning the ropes. My issue at the moment is that I need to add Hbox1 and HBox2 to the content in the tab called tabEnc. At the moment I am getting an error "Children: cycle detected" which from what I understand is that a circular dependency is being created. I have tried numerous times to fix it but maybe I am overlooking something, any help would be greatly appreciated.

The error that comes up is as follows:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Children: cycle detected: parent = TabPane@6f5ca7e2[styleClass=tab-pane], node = TabPaneSkin$TabContentRegion@2d7c1f31[styleClass=tab-content-area]

Essentially where the red line is in the below screenshot I would like the label there to be "Select File" which is contained in a different Hbox to that of the text field and buttons below it as they should be contained in another Hbox.

If my question is missing anything please let me know and I will amend it accordingly.

enter image description here

Main.java

import javafx.application.Application;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.security.Security;

public class Main extends Application {

    private Style clientStyle = new Style();
    @Override
    public void start(Stage primaryStage) {

        primaryStage.setScene(clientStyle.getScene());
        primaryStage.setTitle("NTH Secure");
        primaryStage.getIcons().add(new Image(("styles/lock.png")));
        primaryStage.setResizable(false);
        primaryStage.show();
    }

    public static void main(String[] args) {
        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        launch(args);
    }
}

Style.java

import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;


// A class containing the UI elements of the program
public class Style {
    private Scene scene;
    private TabPane tabPane;
    private String dir = System.getProperty("user.dir")+"/testFiles";

    public Style(){

        BorderPane root = new BorderPane();
        scene = new Scene(root, 500, 300);
        scene.getStylesheets().add(getClass().getResource("styles/application.css").toExternalForm());
        tabPane = new TabPane();
        root.setCenter(tabPane);


        //Tab for encryption
        Tab tabEnc = new Tab("Encrypt");
        tabEnc.setClosable(false);
        //PasswordField passwordTxt = new PasswordField();
        Label selectLabel = new Label("Select File");
        HBox hbox1 = new HBox(selectLabel);
        hbox1.setPadding(new Insets(20, 20, 20, 20));
        hbox1.setSpacing(10);

        TextField fileLabel = new TextField("");
        fileLabel.setEditable(false);
        Button buttonFile = new Button("Select");
        Button buttonClear = new Button("Clear");
        buttonClear.setPrefWidth(70);
        buttonFile.setPrefWidth(80);
        fileLabel.setPrefWidth(350);
        HBox hbox2 = new HBox(fileLabel, buttonFile, buttonClear);
        hbox2.setPadding(new Insets(20, 20, 20, 20));
        hbox2.setSpacing(10);
        root.getChildren().addAll(hbox1, hbox2);
        tabEnc.setContent(root);

        //Tab for decryption
        Tab tabDec = new Tab("Decrypt");
        tabDec.setClosable(false);

        //Tab for information
        Tab tabInf = new Tab("About");
        tabInf.setClosable(false);

        tabPane.getTabs().addAll(tabEnc, tabDec, tabInf);

    }

    public Scene getScene(){
        return this.scene;
    }

}
Mackem2020
  • 61
  • 6

1 Answers1

2

So I managed to solve it. There was a small error on my part: I should have encapsulated them into a Vbox like so:

VBox vbox = new VBox(); 
vbox.getChildren().addAll(hbox1, hbox2); 
tabEnc.setContent(vbox); 
flyingfishcattle
  • 1,817
  • 3
  • 14
  • 25
Mackem2020
  • 61
  • 6