本文介紹了將點(diǎn)擊處理程序添加到 GWT 中的 Horizo??ntalPanel的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
如何將點(diǎn)擊處理程序添加到 Horizo??ntalPanel
?
How do i add click handlers to HorizontalPanel
?
它可以在較新的 GWT 版本中使用 addDomHandler()
,但我不得不降級(jí)到不支持此功能的 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 而不是掛鉤原生事件.捕獲整個(gè)面板的點(diǎn)擊:
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 的單元格內(nèi)捕捉點(diǎn)擊:
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(...);
這篇關(guān)于將點(diǎn)擊處理程序添加到 GWT 中的 Horizo??ntalPanel的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!