0

I have 2 projects; SmallProject, BigProject. SmallProject is a standalone java class, BigProject with 2 fxml and 2 controllers.

In the SmallProject with only one class I can simply set the content of a TitledPane with

     Image image = new Image("file:flower.png");
     ImageView imgView = new ImageView();
     imgView.setImage(image);

     Group root = new Group();
     Scene scene = new Scene(root);
     scene.setFill(Color.BLACK);

     TitledPane tPane = new TitledPane();
     tPane.setContent(imgView);

But on my big project with fxml files and controllers it doesn't work. I have a main GUI and a second GUI and for both of them controller/fxml files.

From Fxml file(Second GUI):

      <TitledPane fx:id="myTPane" animated="false" layoutY="427.0" prefHeight="206.0" prefWidth="264.0" text="My Image"> </TitledPane>

From Controller class(Second GUI):

    //This is working!
    String myText = "Some text here"; 
    myTextFieldName.setText(myText);

    // Try 1
    Image imageNEW = new Image("file:flower.png");
    ImageView imgViewNEW = new ImageView();
    imgViewNEW.setImage(imageNEW);
    myTPane = new TitledPane();
    myTPane.setContent(imgViewNEW);

    //Try 2
    Node rootIcon =  new ImageView(new Image("file:flower.png"));
    myTPane = new TitledPane("Title Change Test", rootIcon);

Both try 1 and 2 are not working(I try them separately not together) but Im able to set the textflied. I cant even change the title of the TitledPane... I dont get any errors when I press a button or something... I suppose I'm doing a minor mistake but what? Would be glad if you can help!

Anarkie
  • 657
  • 3
  • 19
  • 46
  • Why are you creating a new `TitledPane`? Just set the content of the one defined in the FXML file. – James_D Dec 03 '15 at 13:46
  • @James_D Then I get lots of errors one is "Caused by: java.lang.NullPointerException" – Anarkie Dec 03 '15 at 13:58
  • 1
    In that case the connection between your FXML and controller is not correct. Did you annotate the declaration of the titled pane with `@FXML`? – James_D Dec 03 '15 at 14:01
  • @James_D Millions of thanks!!!! Im new to JavaFX and FXML, I did many copy pastes and forgot the "at"FXML :( thank you very much! If it wont be much could you give a link on passing a parameter(object) to second GUI? This is too complicated, http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml I think it should be as simple as putting the object in constructor... – Anarkie Dec 03 '15 at 14:08
  • The second section in the accepted answer to the question you linked ("Setting a Controller on the FXMLLoader") shows how to do that by passing a value in the constructor. – James_D Dec 03 '15 at 14:10

1 Answers1

0

Sorry ... while copy pasting things I forgot to add @FXML to my TitledPane declaration, now works!

Anarkie
  • 657
  • 3
  • 19
  • 46