GWT:打印按钮(GWT : print button)
我正在尝试创建一个打印当前浏览器窗口的按钮。
这是我目前的代码,使用(或者至少它试图使用)JSNI:
private Button print = new Button(constants.print(), new ClickHandler() { @Override public void onClick(final ClickEvent event) { /*-{ if ($wnd.print) { $wnd.print(); return true; } else { return false; } }-*/ } });但是当我点击按钮时,什么都没有发生。 这是我的第一个GWT应用程序,所以我不确定如何实现它。
I am trying to create a button that prints the current browser window.
This is my current code, that uses (or at least it tries to use) JSNI:
private Button print = new Button(constants.print(), new ClickHandler() { @Override public void onClick(final ClickEvent event) { /*-{ if ($wnd.print) { $wnd.print(); return true; } else { return false; } }-*/ } });But when I click the button, nothing happens. It is my first GWT application, so I am not sure about how to implement it.
最满意答案
new Button(constants.print(), new ClickHandler() { @Override public void onClick(final ClickEvent event) { print(); } private native boolean print( ) /*-{ if ($wnd.print) { $wnd.print(); return true; } else { return false; } }-*/; });应该管用! 始终将JSNI放在本地方法中。
new Button(constants.print(), new ClickHandler() { @Override public void onClick(final ClickEvent event) { print(); } private native boolean print( ) /*-{ if ($wnd.print) { $wnd.print(); return true; } else { return false; } }-*/; });Should work! Always place JSNI within a native method.
更多推荐
发布评论