GWT:打印按钮(GWT : print button)

编程入门 行业动态 更新时间:2024-10-28 12:30:07
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.

更多推荐

本文发布于:2023-08-01 01:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   GWT   button   print

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!