簡體   English   中英

如何從scalafx中的控制器獲取TableView的句柄

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

我試圖找到一些示例代碼來從控制器內部更新TableView。 如果可能的話,我想用fxml創建TableView。

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

我的TableView看起來像:

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

另外,交互檢查舞台對象和方法的一種好方法是什么?

為了使用它,您需要將其作為參數傳遞,如下所示:

@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