Exchange information between JavaFX windows

1

Good afternoon, I need to exchange information between different windows with javaFX, I searched the net and I saw that the most common is to use communication of controllers. My scenario is as follows: Home screen the user will select a state in a list and clicking search will open another screen with only the cities of that state. I would like a simple example of how to exchange this information. Thankful.

    
asked by anonymous 16.11.2016 / 20:49

2 answers

0

I do not have the example, but if you post the code you did maybe I can help you with what you want.

I imagine you are using FXML, a way that is perhaps simpler instead of using FXMLLoader you could instantiate the control class normally and then inject the control into FMXL. So you could use the class constructor to get any object you want.

    
23.11.2016 / 17:43
0

Hello, if you can add dependencies in your project I suggest the windowControllerFx lib ( link here ), it facilitates the initialization and creation of Stages (windows) and parameter passing. Using the library would look something like this:

Search Class:

public class FrmLisaCidades extends WindowControllerFx{

    @Override
    public void getFXML(){
      return "/view/tela_busca.fxml";
    }

   private String estado;

   public FrmLisaCidades(String estado){
      super();
      this.estado = estado;
   }

   @Override
   public void initialize(URL location, ResourceBundle resources) {

      List<Cidade> lista = new cidadeDao().getListaByEstado(estado);
      // Demais funções
   }
}

Using the library you do not have to worry about FXMLLoader and Stages, you can also display the screen directly by the controller:

new FrmListaCidades().show();

Can you do without lib? gives, but it's a bit more annoying:

ListaCidadesController controller = meuFxmlLoader.getController();
controller.setEstado(meuEstado); // esse método deve ser criado no controller
    
18.03.2017 / 18:03