[英]How to find out which line was selected in one GWT grid canvas?
I'm working on one GWT grid Canvas like this in the fiddle 我正在像这样在一个GWT网格Canvas上工作
My gridCanvas
Object has horizontal lines represent paths. 我的
gridCanvas
对象的水平线代表路径。 Also the object has vertical lines that represent sections. 此外,对象具有代表部分的垂直线。
I want to know how I could get the user's selection, for example, if the user has selected a route or a section and which route or section is selected. 我想知道如何获得用户的选择,例如,如果用户选择了路线或路段以及选择了哪个路线或路段。
Here a screenshot of case. 这里是案例的屏幕截图 。
Add the event you want to listen to like gridCanvas.addClickHandler(ClickHandler)
and use the ClickEvent
to obtain the mouse position and calculate the cell the user clicked on. 添加要侦听的事件,例如
gridCanvas.addClickHandler(ClickHandler)
并使用ClickEvent
获取鼠标位置并计算用户单击的单元格。
gridCanvas.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
int row = event.getY() / getCellHeight();
int col = event.getX() / getCellWidth();
}
});
With getX()
and getY()
, you obtain the position of the mouse. 使用
getX()
和getY()
,您可以获得鼠标的位置。 Since you constructed the grid, you should also have the width and height of a cell. 由于构建了网格,因此还应该具有单元的宽度和高度。 With this information, it is then easy to get the row and/or column.
有了这些信息,就很容易获得行和/或列。
I made a full sample that you can find here . 我做了一个完整的样本,您可以在这里找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.