The Object richtextarea of java gwt has as default the font-family 'times new roman' is it somehow possible to change the family to 'Arial'?
You have several options. You can create a CSS class and set it on the body element of the document inside RichTextArea, or you can set the style attribute on it directly. If you want this change to be consistent throughout your app, I recommend creating a new class and adding an InitializeHandler to it.
public class MyRichTextArea extends RichTextArea {
public MyRichTextArea() {
addInitializeHandler(new InitializeHandler() {
@Override
public void onInitialize(InitializeEvent ie) {
Document document = IFrameElement.as(getElement()).getContentDocument();
BodyElement body = document.getBody();
body.setAttribute("style", "font-family: Arial Unicode MS,Arial,sans-serif;");
});
}
}
}
It is better to use the provided functionality. If you want to change it at creation time, you will need the initializeHandler as mentioned in answer 1:
RichTextArea rta = new RichTextArea();
rta.addInitializeHandler(new InitializeHandler() {
public void onInitialize(InitializeEvent event) {
rta.getFormatter().setFontName("\"Trebuchet MS\",Trebuchet,Arial");
rta.getFormatter().setFontSize(FontSize.SMALL);
rta.getFormatter().setForeColor("#FF0000");
}
});
PS: you need to do this before you add any content to the textarea, or it will only be applied to new input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With