2014-11-22 141 views
0

我在我的TableView中有一個ComboBoxTableCell,當有人單擊ComboBoxTableCell時,我希望另一個窗格顯示在具有項目列表的ComboBoxTableCell下面。我試圖獲得ComboBoxTableCell的座標,但沒有運氣。有什麼方法可以獲得座標嗎?或者你有更好的方法來做到這一點?下面是示例UI的圖像,我想要完成。謝謝。如何獲取TableView JavaFX中TableCell的X和Y座標?

This is the sample UI I want to be done.

這裏是我的方法來初始化的TableView

私人無效initOrderTable(){

this.orderTable.setEditable(true); 
    TableColumn nameCol = new TableColumn("Name"); 
    nameCol.setMinWidth(100); 

    nameCol.setCellValueFactory(
    new PropertyValueFactory<>("name")); 
    nameCol.setCellFactory(new Callback<TableColumn<Product, String>,ComboBoxTableCell<Product,String>>() { 

     @Override 
     public ComboBoxTableCell<Product, String> call(TableColumn<Product, String> param) { 

      ComboBoxTableCell ct= new ComboBoxTableCell<>(); 
      ct.setComboBoxEditable(true); 

      return ct; 
     } 
}); 


    this.orderTable.getItems().addAll("Sample Row"); 
    this.orderTable.getColumns().addAll(nameCol); 

} 
+0

你能顯示一些代碼嗎? – 2014-11-22 13:55:19

回答

1

你可以得到電池相對的座標爲Scene

Point2D location = ct.localToScene(0, 0); 

或相對於Screen with

Point2D location = ct.localToScreen(0, 0); 

這些會給你單元格左上角的座標。你可以做

Point2D location = ct.localToScene(0, ct.getHeight()); 

得到左下方相對的座標爲Scene,等等。很明顯,你將需要設置細胞上的監聽器被調用時,你需要顯示面板。

+0

謝謝詹姆斯,它的工作原理.. – 2014-11-22 15:38:01