{"action":"created","issue":{"url":"https://api.github.com/repos/edvin/tornadofx/issues/90","repository_url":"https://api.github.com/repos/edvin/tornadofx","labels_url":"https://api.github.com/repos/edvin/tornadofx/issues/90/labels{/name}","comments_url":"https://api.github.com/repos/edvin/tornadofx/issues/90/comments","events_url":"https://api.github.com/repos/edvin/tornadofx/issues/90/events","html_url":"https://github.com/edvin/tornadofx/issues/90","id":148963050,"number":90,"title":"incapsulate a custom `ListCell`","user":{"login":"voddan","id":5666566,"avatar_url":"https://avatars.githubusercontent.com/u/5666566?v=3","gravatar_id":"","url":"https://api.github.com/users/voddan","html_url":"https://github.com/voddan","followers_url":"https://api.github.com/users/voddan/followers","following_url":"https://api.github.com/users/voddan/following{/other_user}","gists_url":"https://api.github.com/users/voddan/gists{/gist_id}","starred_url":"https://api.github.com/users/voddan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voddan/subscriptions","organizations_url":"https://api.github.com/users/voddan/orgs","repos_url":"https://api.github.com/users/voddan/repos","events_url":"https://api.github.com/users/voddan/events{/privacy}","received_events_url":"https://api.github.com/users/voddan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-17T15:19:44Z","updated_at":"2016-04-17T16:19:09Z","closed_at":null,"body":"I am trying to incapsulate a custom `ListCell` in a class. \r\n\r\nNow I have (btw, it works):\r\n```\r\nclass MyListView(list: List<Int>): ListView<Int>() {\r\n    init {\r\n        items.addAll(list)\r\n        \r\n        setCellFactory { listView ->\r\n            object : ListCell<Int>() {\r\n                override fun updateItem(item: Int?, empty: Boolean) {\r\n                    super.updateItem(item, empty)\r\n                    if(item == null || empty) return\r\n\r\n                    graphic = HBox().apply {.....}  // gonna incapsulate that in a UI element somehow \r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\nI tried to create a `class ListItemView : View() {override val root = ...}`, but the problem is that `View` is somehow not a `Node`, so it is impossible to pass it there.\r\n\r\nWhat is the recommended way?"},"comment":{"url":"https://api.github.com/repos/edvin/tornadofx/issues/comments/211051025","html_url":"https://github.com/edvin/tornadofx/issues/90#issuecomment-211051025","issue_url":"https://api.github.com/repos/edvin/tornadofx/issues/90","id":211051025,"user":{"login":"edvin","id":977035,"avatar_url":"https://avatars.githubusercontent.com/u/977035?v=3","gravatar_id":"","url":"https://api.github.com/users/edvin","html_url":"https://github.com/edvin","followers_url":"https://api.github.com/users/edvin/followers","following_url":"https://api.github.com/users/edvin/following{/other_user}","gists_url":"https://api.github.com/users/edvin/gists{/gist_id}","starred_url":"https://api.github.com/users/edvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edvin/subscriptions","organizations_url":"https://api.github.com/users/edvin/orgs","repos_url":"https://api.github.com/users/edvin/repos","events_url":"https://api.github.com/users/edvin/events{/privacy}","received_events_url":"https://api.github.com/users/edvin/received_events","type":"User","site_admin":false},"created_at":"2016-04-17T16:19:09Z","updated_at":"2016-04-17T16:19:09Z","body":"A `View` has a `root` property of type `Node`. This `Node` can be inserted into any scene graph, but you need to remember that `View` is a singleton, so the `root` of a `View` should never go into a `ListCell`.\r\n\r\nA `Fragemnt` however is \"prototype\" scoped, and can be used that way.\r\n\r\nThat said, I think you are going about this the wrong way. Normally, you would create a `View` and let the ListView be your `root` node. The above code would look like this using the type safe builders:\r\n\r\n```kotlin\r\nclass MyListView(items: ObservableList<String>) : Fragment() {\r\n    override val root = ListView<String>(items)\r\n\r\n    init {\r\n        root.cellFormat {\r\n            graphic = HBox().apply { ... }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nAs you can see, the `cellFormat` function takes all the grunt work out of creating ListCells. You don't need to check if the item is null etc, just configure that text/graphic you want when there is an actual entry for the current cell.\r\n\r\nI didn't quite grasp what you're trying to accomplish at the `graphic = ` line. Please elaborate, and I'll show you \"the TornadoFX\" way :)"}}