The TableView
class of JavaFX 2.2 has a generic type S
, I am wondering how one can set this from FXML?
问题:
回答1:
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.
回答2:
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.
回答3:
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.