GWT UiBinder:将鼠标处理程序添加到面板或网格

发布于 2024-09-27 01:06:45 字数 485 浏览 2 评论 0原文

我找不到将鼠标处理程序添加到 GWT 面板或网格的方法 在使用 UiBinder 时。

我基本上需要一种可以在网格上检测以下内容的方法:

  1. 检测正在发生事件的单元格。
  2. 检测鼠标弹起事件
  3. 检测鼠标按下事件
  4. 检测鼠标移出事件
  5. 检测鼠标悬停事件

我计划尝试使用绝对面板覆盖在 网格的顶部。我可以在 AbsolutePanel 上检测到这些事件, 然后根据事件发生的位置,确定哪个单元格 如果没有 AbsolutePanel,事件就会发生 覆盖在网格顶部,然后进行相应的操作。我现在发现 在术语上对面板施加完全相同的限制 点击处理程序,并且没有太多选项。

我只需要找到一种方法让上述事件在网格上运行。 你会推荐什么?没有使用 UiBinder,我使用的是 DomHandlers, 这似乎在 UiBinder 中被禁用(我错了吗?)。

非常感谢任何帮助。谢谢!

〜斯科特

I can't find a way to add a Mouse Handler to a GWT Panel or a Grid
while using UiBinder.

I basically need a way that I can detect the following over a Grid:

  1. Detect what cell the event is happening in.
  2. Detect Mouse Up Event
  3. Detect Mouse Down Event
  4. Detect Mouse Out Event
  5. Detect Mouse Over Event

I had planned to try and do this with the absolute panel overlayed on
top of the Grid. I could detect these events on the AbsolutePanel,
then based off of the location of the event, determine what cell the
event would have taken place in had the AbsolutePanel not have been
overlayed on top of the Grid, and then act accordingly. I now find out
that the exact same restrictions are placed upon the panels in terms
of click handlers, and don't have many options.

I just need to find a way to get the above events to work on the Grid.
What would you recommend? Not using UiBinder, I was using DomHandlers,
which seem to be disabled in UiBinder (am I wrong?).

Any help is VERY appreciated. Thanks!

~Scott

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三岁铭 2024-10-04 01:06:45

您可以扩展 Grid 并让它实现适当的接口,例如:

public class ClickableGrid extends Grid implements HasMouseDownHandlers {
     ...
    public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
        return addDomHandler(handler, MouseDownEvent.getType());
    }

}

然后在模板中使用它

<my:ClickableGrid ui:field="clickableGrid">

并在所属类中添加处理程序

@UiHandler("clickableGrid")
    void handleClick(MouseDownEvent event) {
...
}

希望它有所帮助。

You could extend Grid and have it implement appropriate interfaces like:

public class ClickableGrid extends Grid implements HasMouseDownHandlers {
     ...
    public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
        return addDomHandler(handler, MouseDownEvent.getType());
    }

}

and then use it in template

<my:ClickableGrid ui:field="clickableGrid">

and add handler in owning class

@UiHandler("clickableGrid")
    void handleClick(MouseDownEvent event) {
...
}

Hope it helps.

晨敛清荷 2024-10-04 01:06:45

...或者简单地将 Grid 放置在 FocusPanel 中:

public class MouseGrid extends Composite {

    public MouseGrid() {
        Grid grid = new Grid(3, 3);
        for (int row = 0; row < 3; ++row) {
            for (int col = 0; col < 3; ++col) {
                grid.setText(row, col, "" + row
                        + ", "
                        + col);
            }
        }
        FocusPanel panel = new FocusPanel();
        panel.setWidget(grid);
        initWidget(panel);
        panel.addMouseDownHandler(new MouseDownHandler() {

            @Override
            public void onMouseDown(MouseDownEvent event) {
                Window.alert("mouse down");
            }
        });
    }
}

...or simply place the Grid inside a FocusPanel:

public class MouseGrid extends Composite {

    public MouseGrid() {
        Grid grid = new Grid(3, 3);
        for (int row = 0; row < 3; ++row) {
            for (int col = 0; col < 3; ++col) {
                grid.setText(row, col, "" + row
                        + ", "
                        + col);
            }
        }
        FocusPanel panel = new FocusPanel();
        panel.setWidget(grid);
        initWidget(panel);
        panel.addMouseDownHandler(new MouseDownHandler() {

            @Override
            public void onMouseDown(MouseDownEvent event) {
                Window.alert("mouse down");
            }
        });
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文