tags:

views:

253

answers:

4

Is there a way to display HTML in a GWT Panel?

+2  A: 

Ahhh. I was thinking about it differently. It's the widget I'm putting into the panel that needs to be formatted. Therefore if I do a

HTML example = new HTML(someText)

then add it to a panel it'll work :)

day_trader
+4  A: 

Short Answer: You can add HTML to a GWT Panel by creating an HTML widget and attaching that widget to your panel. For example...

HorizontalPanel hp = new HorizontalPanel();
HTML html = new HTML("<p>This is html with a <a href='www.google.com'>link</a></p>");
hp.add(html); // adds the widget to the panel

Long Answer: There are a variety of ways that you can add HTML to a GWT Panel. You should start by reading the Developer's Guide for GWT. Specifically, you should read the portions on Layout Using Panels and Widgets.

prometheus
+1  A: 
import com.google.gwt.user.client.ui.HTML;

import com.google.gwt.user.client.ui.RootPanel;

RootPanel.get().add(new HTML("<b>Gwt Html</b>"));

you can add this HTML widget to any panel with "panel.add(widget);" code

Kerem
+3  A: 

Also, the new declarative UI stuff in GWT 2.0 saves you from having to embed HTML into your Java.

<g:HTMLPanel>
   Here <strong>is some HTML</strong>.
</g:HTMLPanel>
AlexJReid