Reputation: 55
Here's my listView:
public ListView<Consulta> lstViewLista;
Here I want my listView like it is (listView<Consulta>
):
public void btnDireitaOnAction(ActionEvent event){
ObservableList<Consulta> consultaData = FXCollections.observableArrayList();
try {
consultaData.addAll(ConsultaDAO.buscarPorData(Agenda.getData()));
} catch (Exception e) {
System.err.println("Erro: Impossível encontrar as consultas.");
e.printStackTrace();
}
lstViewLista.setItems(consultaData);
}
But here I want my listView like listView<Paciente>
:
public void btnDireitaOnAction(ActionEvent event){
ObservableList<Paciente> pacienteData = FXCollections.observableArrayList();
try {
pacienteData.addAll(PacienteDAO.buscarPorData(Agenda.getData()));
} catch (Exception e) {
System.err.println("Erro: Impossível encontrar os pacientes.");
e.printStackTrace();
}
lstViewLista.setItems(pacienteData);
}
How can I change between them? Someone help T_T
Upvotes: 0
Views: 108
Reputation: 1498
You define lstViewLista
as being a ListView
of type <Consulta>
, so it's probably not wise to change it's type. Why not have two ListView
s, one of type <Consulta>
and one of type <Paciente>
, like this?
ListView<Consulta> lstViewConsulta;
ListView<Paciente> lstViewPaciente;
You could switch which one is showing by either adding and removing it from it's parent node using Node.getChildren()
or by using setManaged() and setVisible() like this:
//hide lstViewConsulta and show lstViewPaciente
lstViewConsulta.setVisible(false);
lstViewConsulta.setManaged(false);
lstViewPaciente.setVisible(true);
lstViewPaciente.setManaged(true);
Upvotes: 1