How to Make a RichTextArea with the tool bar like in the samples

4k Views Asked by At

I have already searched on stackoverflow my same question and I found someone with the same question but I could not fix my problem with the answer from that question. Anyways I am new to GWT and when I tried to make a RichTextArea, I thought it would make something that would look like the sample in http://www.gwtproject.org/doc/latest/RefWidgetGallery.html (scroll down till you see RichTextArea) but instead there is just a plain text area without a tool bar. How come there is no tool bar in mine? Can someone help me and can you show me how to change my code so that it looks like the sample. Also I figured that it might have something to do with the Formatter or the getFormatter method if it does can you show me how to do that. here is my code:

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.RichTextArea.Formatter;
import com.google.gwt.user.client.ui.RootPanel;

public class Widgets implements EntryPoint 
{
private Button btn;
private Button cbtn;
private RichTextArea textArea;



    public void onModuleLoad() 
    {
         btn = new Button("Submit");
         cbtn = new Button("Clear");
         textArea = new RichTextArea();
         Formatter format = textArea.getFormatter();

         cbtn.addClickHandler(new ClickHandler(){

        public void onClick(ClickEvent event) {
        textArea.setText("");   
        }
    });

    RootPanel.get().add(textArea);
    RootPanel.get().add(btn);
    RootPanel.get().add(cbtn);
    }

}
3

There are 3 best solutions below

1
On

Take a look at the GWT Showcase, Here. In the source code you can see that there is a RichTextToolbar, which you need to instantiate and associate with the RichTextArea.

0
On

The RichTextToolbar in GWT Showcase is not included into GWT (see this issue). It's only for the sample.

You have to write your own toolbar. You can also download the source code of the sample here and adapt it to your needs.

0
On

The RichTextToolbar does not come with gwt-user jar. For some strange reason it is only coded and checked in "Showcase" demo code.

Code - You can find the code for RichTextToolbar in the gwt source for samples.

Demo - Take a look at the GWT Showcase, Here.

We ended up duplicating this class in our source code as it is not present in gwt jars.