Setting TableView generic type from FXML?

℡╲_俬逩灬. 提交于 2019-12-23 09:59:44

问题


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.



来源:https://stackoverflow.com/questions/16010633/setting-tableview-generic-type-from-fxml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!