5

The TableView class of JavaFX 2.2 has a generic type S, I am wondering how one can set this from FXML?

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270

3 Answers3

5

The same happens to a ListView or ComboBox. But I think that in the FXML file you are defining the controls and you are defining a generic ListView or a ComboBox or TableView or whatever. No matter what they are going to show.

So to me it makes more sense to set the generic type in the JavaFX controller class, instead of in the FXML file.

Hope it helps.

Antonio J.
  • 1,750
  • 3
  • 21
  • 33
  • Thank you Antonio, I've also just seen that you set this in the controller :-) So I guess the FXML parser first looks at the controller class before instantiating the TableView and takes the generic type from there. Would make sense :-) – stefan.at.kotlin Apr 15 '13 at 08:53
  • Good to see it helps you. Happy coding! :-) – Antonio J. Apr 15 '13 at 10:43
5

FXML is dynamically loaded at runtime. Since generic types are erased at compile time, it doesn't make sense to define them in markup. Defining the generic in the controller class is correct.

Greg Brown
  • 3,168
  • 1
  • 27
  • 37
0

Normally I would agree with the replies here, but when you are using Scene Builder to develop your GUIs and then wish to import the skeleton controller parts into your code for the updates you have made it is really annoying to have to remember to go back and replace all of the [?] and [?, ?] with the actual class names. It would be nice if either the FXML spec or Scene Builder allowed you to specify the template classes.