简体   繁体   English

如何找出在一个GWT网格画布中选择了哪条线?

[英]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 . 我做了一个完整的样本,您可以在这里找到。

The sample is deployed here . 该示例已部署在此处

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

相关问题 如何找出所选文本的行号? - How to find out line numbers of selected text? 如何找出GWT(客户端)中缺少哪些Java类? - How to find out which Java classes are missing in GWT (client side)? 如何找出是否选中了多个复选框 - How to find out if more then one checkbox was selected 如何找出用户选择了哪个单选按钮以与 Android 中 QuestionApp 中的正确单选按钮进行比较 - How to find out which radiobutton has been selected by the user for comparing with the correct one in QuestionApp in Android 如何找出选择了哪个自动生成的复选框? - How to find out which automatic generated checkbox is selected? 列表网格字段中的智能GWT滚动画布 - Smart GWT RollOver Canvas in List Grid fields 如何找出用于分割行的行分隔符 BufferedReader#readLine()? - How to find out which line separator BufferedReader#readLine() used to split the line? 如何查找具有一列值相同的多行并添加到一行并设置为vaadin网格 - how to find muliple rows which has one column value same and add to one row and set to vaadin grid 如果用户在JTreeTable SwingX中选择一行,那么如何找出实际选择了哪个节点 - If the user selects a row in a JTreeTable SwingX, how do I find out which node is actually selected 按钮单击方法如何找出在ListView中选择了哪个项目? - How can a button click method find out which item is selected in a ListView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM