简体   繁体   中英

Cant control JavaFX TitledPane with FXML

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!

抱歉...复制粘贴内容时忘记将@FXML添加到我的TitledPane声明中,现在可以使用了!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM