That is usually what you would do. That is how GWT itself implements
widgets and it does not really matter if you use an elemental2 element or a
GWT element since both link directly to the underlying js type in the
browser and thus you can cross cast them.
So instead of just having an adapter widget you could also implement your
own widgets using elemental2 element as a basis. Imagine you would rename
your Elemental2Widget to Artboard or SceneCanvas and then you could
implement all the methods you need on that widget similar to what GWT does
with its own widgets.
What you cannot do is elemental2Element.append(gwtWidget.getElement()). In
that case events on the GWT widget will not work because GWT widgets have
their own event mechanism which requires a continuous widget parent/child
relation up to the root panel (or some hackery to make it work).
-- J.
Craig Mitchell schrieb am Mittwoch, 30. Juli 2025 um 06:34:49 UTC+2:
> I've switched to use Elemental2 for a few things. The rest of my app
> still uses the standard GWT widgets.
>
> I can bind directly to the Elemental2 elements from the GWT UI Binder,
> however, if I programatically want to add an Elemental2 element to a GWT
> Widget, there doesn't seem to be a direct way to do this.
>
> Eg: How would you add the Elemental2 HTMLCanvasElement, to a
> GWT SimplePanel using its setWidget method?
>
> To work around this, I created an "Elemental2Widget":
>
> import com.google.gwt.dom.client.Element;
> import com.google.gwt.user.client.ui.Widget;
> import jsinterop.base.Js;
>
> public class Elemental2Widget<T> extends Widget {
> public Elemental2Widget(T elemental2Widget) {
> Element element = Js.cast(elemental2Widget);
> setElement(element);
> }
> public T getElemental2Widget() {
> return Js.cast(getElement());
> }
> }
>
> Now I can call it like this:
>
> simplePanel.setWidget(new Elemental2Widget<>(htmlCanvasElement));
>
> Is this how people mix Elemental2 with GWT widgets? Or is there a better
> way?
>
>
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/google-web-toolkit/17b81a23-fc5b-4577-a72e-3c9105ca8c8fn%40googlegroups.com.