简体   繁体   中英

GWT can't define canvas on existing element

I have an element defined as a HTML element, namely <canvas id = 'foo' width = '25' height = '40'></canvas> . I am trying to draw to it like this:

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
Canvas canvas2 = Canvas.createIfSupported();
Element el = DOM.getElementById("foo");
canvas2.setElement(el);

The last line is throwing an error in Eclipse, error message being The method setElement(Element) from the type UIObject is not visible . What should I do to correct it? This is the list of classes I am importing, is there any JAR conflict?

import com.google.gwt.canvas.client.Canvas;
import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

Unfortunately there is no easy way to do this currently. Issue #6683 is open for that in GWT's issue tracker. The suggested workaround is to copy the Canvas widget class and loose the visibility of the constructor... not very convenient I admit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM