Dan
unread,Nov 21, 2009, 8:27:15 AM11/21/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
You can do it with a class and a way to pass a string to it.
// ========= class code ===============
public class PrintWidgetClass2 {
native void printx(String s) /*-{
var win1 = window.open('', 'reportwindow');
win1.document.open();
win1.document.write("<head><title>Report</title>");
win1.document.write("<style> body,td {font-family:sans-serif;font-
size:10pt;}</style>");
win1.document.write("<script> \r\n")
win1.document.write("function Print(){window.print()}</script>")
win1.document.write("</head><body onload=\"Print()\">");
win1.document.write(s);
win1.document.write("</body></html>");
win1.document.close();
}-*/;
public void printIt(String html){
printx(html);
}
}
// ========== end of class code ============
Now for a way to call it. Say you have a widget (panel, whatever) that
you want to print. Use this code:
// ========= begin calling code ===========
StringBuffer sb = new StringBuffer();
sb.append(titlePanel.getElement().getString());
sb.append(header.getElement().getString());
sb.append(dataList.getElement().getString());
PrintWidgetClass2 cc = new PrintWidgetClass2();
cc.printIt(sb.toString());
// ========== end of calling code ==========
Notice that in this case the code puts together several widgets, not
just one, and prints the combined result