0

I'm trying to develop a fxml window where are huge number of check boxes. I know i can handle those check boxes by fx:id for each check boxes separately. Is there any way to handle those check boxes easily? Here is a snapshot of my fxml window created using Gluon Scene Builder

FXML Scene containing multiple checkboxes:

Etibar
  • 578
  • 6
  • 22
  • 3
    If you have such high number of checkboxes, I would recommend to not use FXML. – ItachiUchiha Jan 26 '18 at 10:28
  • Then what should I use & how? – Asswad Sarker Nomaan Jan 26 '18 at 10:36
  • 3
    You could generate all the CheckBox using a simple loop in Java code – ItachiUchiha Jan 26 '18 at 10:40
  • Ok, thanks for the suggestion. @ItachiUchiha – Asswad Sarker Nomaan Jan 26 '18 at 10:44
  • 2
    You can also use a `TableView` with a `CheckBoxCell` for each cell, then they are handled by the `TableView`. – Sunflame Jan 26 '18 at 10:55
  • @ItachiUchiha is right. You can add a Listener to each other witch get Checkbox Object... or bind its in loop. – kozmo Jan 26 '18 at 11:20
  • `Map map = new HashMap<>(); for (int i = 1; i <= 100; i++) { String s = String.valueOf(i); CheckBox cb = new CheckBox(); cb.setId(s); cb.addEventHandler(ActionEvent.ACTION, e-> System.out.println("AAAAAAAAAAAAAAAAA"); ); map.put(s,cb); }` – kozmo Jan 26 '18 at 11:42
  • You can also consider creating a [custom component](https://docs.oracle.com/javase/9/docs/api/javafx/fxml/doc-files/introduction_to_fxml.html#custom_components) for the label with the number and the three checkboxes. Then use a loop in your main controller to create the 31 instances of it. – James_D Jan 26 '18 at 12:36
  • Thanks everybody. I used TableView with CheckBoxCell as suggested by @Sunflame – Asswad Sarker Nomaan Jan 26 '18 at 13:05

0 Answers0