Access fields from another Controller in JavaFX

蹲街弑〆低调 提交于 2019-11-28 12:53:42

Expose properties in the "nested" controllers StreamController and PlayController. Those controllers can bind the properties to the UI components they define as needed.

Then inject the nested controllers into MainController as described in the Nested Controllers section of the Introduction to FXML.

Update: Here's a more similar example, where the interacting controllers are both included in a common FXML.

You need to send your Fxmlloader from controller to other ,i mean create a method in playController to get your fxmloader from StreamController.

public class PlayController implements Initializable {

pulic StreamController stream;
@FXML
private TextField searchField;

@FXML
protected void search() {
    System.out.println("Search");
    String text = searchField.getText();
   //how to access Label in StreamControlle
    stream._yourLabeL ....

}
public StreamController StreamController(){
      return stream;
} 
public StreamController setStreamController(StreamController streamController){
      stream=streamController
}

and in class that contain fxml loader add this line

StreamController streamcontroller=myStreamFxml.getController();
 new PlayController().setStreamController(streamController);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!