I am currently working on a software module consisting of searching in a database using JavaFx. Everything is working as expected. But the only problem is that in my result table I am showing only few details of search (from UX issues: I have too much details and long texts). What I would like to do is to show a new window with all details of a clicked row in TextFields and TextArea. I looked at several tutorials and answers, but unfortunately nothing is working. Any help would be appreciated! Thank you.
SearchResult.setOnMouseClicked(new EventHandler<MouseEvent>() {
Gemo temp;
@Override
public void handle(MouseEvent event) {
Gemo row = SearchResult.getSelectionModel().getSelectedItem();
if(row == null) {
System.out.print("I am not in");
return ;
}
else {
temp = row;
String id = String.format(temp.getRef());
System.out.println(id);
FXMLLoader loader=new FXMLLoader();
loader.setLocation(getClass().getResource("DetailsWindow.fxml"));
ControllerDetails gemodetails=loader.getController();
ControllerDetails gd=new ControllerDetails();
gd.SearchById(id);
try{
loader.load();
} catch (IOException e) {
e.printStackTrace();
}
Parent p= loader.getRoot();
Stage stage=new Stage();
stage.setTitle("More Details");
stage.setScene(new Scene(p));
stage.show();
}
}
});
public class ControllerDetails {
@FXML
private TextField fn_patient;
@FXML
private TextField ln_patient;
@FXML
private TextField db_patient;
@FXML
private TextField id_patient;
@FXML
private TextField id_visit;
@FXML
private TextField date_visit;
@FXML
private TextField fn_user;
@FXML
private TextField ln_user;
@FXML
private TextField status;
@FXML
private TextArea com;
@FXML
public void initialize(){
}
public void SearchById(String id) {
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
connection = ConnectionConfiguration.getConnection();
statement = connection.prepareStatement("my_sql_query");
rs = statement.executeQuery();
while (rs.next()) {
id_visit.setText(rs.getString(1));
id_patient.setText(rs.getString(2));
date_visit.setText(rs.getString(3));
com.setText(rs.getString(4));
fn_patient.setText(rs.getString(5));
ln_patient.setText(rs.getString(6));
db_patient.setText(rs.getString(7));
fn_user.setText(rs.getString(8));
ln_user.setText(rs.getString(9));
status.setText(rs.getString(10));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}