2014-11-22 70 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