I started a javafx project that interact with a database (add new, edit, delete, find,...).
My database contains a lot of tables, and each table requires its own scene (which are almost the same!!!).
so My problem is: instead of implementing ~20 fxml file, is it possible to make a single fxml file that will change its content based on the Class name (for example) passed to its controller?
if yes, any tips to achieve it?
Here is what I have tried:
added a HashMap for each TableClass containing all the attributes needed to be in the scene and and iterate through it in a ControllerClass to add the control to the scene!!! but FAILED!
TableSampleClass:
public class TableSampleClass{
public static final HashMap<String, String> attr;
static {
attr = new HashMap<String, String>();
attr.put("ref", "text");
attr.put("name", "text");
attr.put("adress", "text");
attr.put("Mobile", "tel");
attr.put("mail", "mail");
attr.put("isalive", "checkbox");//just to illustrate what i want !
}
........
}
ControllerClass:
@FXML
private AnchorPane pane;
@Override
public void initialize(URL location, ResourceBundle resources)
{ Iterator it = TableSampleClass.attr.entrySet().iterator();
while(it.hasNext())
{
Map.Entry pair = (Map.Entry)it.next();
switch (pair.getValue().toString()){
case "text":
TextField txt =new TextField(pair.getValue().toString());
txt.setPromptText(pair.getKey().toString());
Label lbl =new Label(pair.getKey().toString());
pane.getChildren().add(txt);
break;
}
}
}
I hope I did explain myself clearly !!