简体   繁体   English

在ScalaFX中,如何获取鼠标下方的表行?

[英]In ScalaFX how to get which table row is under the mouse?

I have a tableView of person. 我有一个人的tableView。 every time i pass the mouse over a person row, i want to show some information about it . 每当我将鼠标移到某个人的行上时,我都想显示一些有关它的信息。 ( the information can be showed in a textArea for example). (例如,信息可以显示在textArea中)。 Thanx 谢谢

Can you assign the onMouseEntered property of the TableCell instances in your TableView value? 您可以在TableView值中分配TableCell实例的onMouseEntered属性吗?

A custom cell value factory can be used to provide instances of an application-specific cell subclass. 自定义单元格值工厂可用于提供特定于应用程序的单元格子类的实例。 This allows the custom cell to assign its own event handling function to the event handling property defined by Node. 这允许自定义单元将其自己的事件处理功能分配给Node定义的事件处理属性。 For example, try this in the custom subclass of TableCell provided by the cell value factory: 例如,在单元值工厂提供的TableCell的自定义子类中尝试以下操作:

  onMouseEntered = (event: MouseEvent) => {
    info(s"onMouseEntered cell ${index()}: $event")
    event.consume()
  }

TableCell.index() provides the current index of the cell in the TableView. TableCell.index()提供TableView中单元格的当前索引。

If you don't get the value you expect it might be because cells are recycled. 如果您没有获得所需的价值,那可能是因为回收了细胞。 If you scroll through a large table the TableView will use a technique called "virtualization" to reuse the cell instances by associating an existing cell with different content, eg the first cell that you can see might be the 100th cell in the table. 如果滚动查看大表,则TableView将使用一种称为“虚拟化”的技术,通过将现有单元格与不同的内容相关联来重用单元格实例,例如,您看到的第一个单元格可能是表中的第100个单元格。

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

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