简体   繁体   English

如何从scalafx中的控制器获取TableView的句柄

[英]How to get a handle to the TableView from the controller in scalafx

I'm trying to find some sample code to update my TableView from inside my controller. 我试图找到一些示例代码来从控制器内部更新TableView。 If possible I want to make my TableView with fxml. 如果可能的话,我想用fxml创建TableView。

def addPerson(event: ActionEvent) {
  // how do I access my TableView items?
}

My TableView looks like: 我的TableView看起来像:

<TableView fx:id="tableView"></TableView>

Also, what's a good way to interactively inspect stage objects and methods? 另外,交互检查舞台对象和方法的一种好方法是什么?

In order to use it, you need to pass it in as a parameter which will be shown below : 为了使用它,您需要将其作为参数传递,如下所示:

@sfxml
class PersonOverviewController(

    private val tableView : TableView[S] //S -> The type of the objects contained within the TableView items list.

    ) {

    def addPerson(event: ActionEvent) {
        // do whatever you want here with tableView
        val selectedIndex = tableView.selectionModel().selectedIndex.value //just for example 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM