Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a h1 tag with gwt

Well the question might seem stupid but I really can't figure it out. How can you add dynamically a html heading tag to your page using the google web toolkit.

I don't want to do this for the style of the heading as I could add any style to any label, it is because I want to use the jqueryui accordion it works with a pair of header and content panel.

How can I do this?

like image 932
David Avatar asked Feb 15 '12 21:02

David


2 Answers


Yes this is kinda complicated to say the least.... Here is the easiast example I can think of:

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.HeadingElement;

...

HeadingElement headingElement = Document.get().createHElement(1);
headingElement.setInnerText("This is a Heading1 (h1) element!");
RootPanel.get().getElement().appendChild(headingElement);

If you look at the other methods of the Document.get().... you will find methods for creating all other HTML elements too.

Addition:

This might be even easier:

import com.google.gwt.user.client.ui.HTML;
.....
HTML headingElement= new HTML();
headingElement.setHTML("<h1>This is a Heading1 (h1) element!</h1>");        
RootPanel.get().getElement().appendChild(headingElement);
like image 116
Stefan Avatar answered Oct 08 '22 13:10

Stefan


You can also use HTMLPanel and specify which tag to use in the constructor:

HTMLPanel header = new HTMLPanel ("h1", "bla bla bla");

should produce

<h1>bla bla bla</h1>
like image 32
Ivan Poliakov Avatar answered Oct 08 '22 14:10

Ivan Poliakov