本文介紹了將點擊處理程序添加到 GWT 中的 Horizo??ntalPanel的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何將點擊處理程序添加到 Horizo??ntalPanel
?
How do i add click handlers to HorizontalPanel
?
它可以在較新的 GWT 版本中使用 addDomHandler()
,但我不得不降級到不支持此功能的 GWT 2.0.4.我以前是這樣的:
It worked with the use of addDomHandler()
in newer GWT versions, but i had to downgrade to GWT 2.0.4 where this isn't supported. I used to do it like this:
horizontalPanel.getWidget(1).addDomHandler(someClickHandler,ClickEvent.getType());
//or
horizontalPanel.addDomHandler(someClickHandler, ClickEvent.getType());
推薦答案
使用 FocusPanels 而不是掛鉤原生事件.捕獲整個面板的點擊:
Use FocusPanels instead of hooking native events. To catch clicks for the whole panel:
FocusPanel wrapper = new FocusPanel();
HorizontalPanel panel = new HorizontalPanel();
wrapper.add(panel);
wrapper.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// Handle the click
}
});
// Add wrapper to the parent widget that previously held panel.
或者在 Horizo??ntalPanel 的單元格內捕捉點擊:
Or to catch clicks inside a cell in the HorizontalPanel:
IsWidget child; // Any widget
HorizontalPanel panel = new HorizontalPanel();
FocusPanel clickBox = new FocusPanel();
clickBox.add(child);
panel.add(clickBox);
clickBox.addClickHandler(...);
這篇關于將點擊處理程序添加到 GWT 中的 Horizo??ntalPanel的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!