Gwt 如何设置RichTextBox的样式? RichTextBox有这样的dom层次结构吗?
在这个boy元素上抛出了一个NullPointerException,甚至我也这样包装它们:Gwt 如何设置RichTextBox的样式? RichTextBox有这样的dom层次结构吗?,gwt,ri,Gwt,Ri,在这个boy元素上抛出了一个NullPointerException,甚至我也这样包装它们: 实际上,问题是RichTextBox在附加到 DOM,它的内部内容(html,body)没有生成,甚至我将这些行包装到 onload()方法,NPE有时会被抛出,但如果将它们包装到计时器中,则计划 一个相对较长的等待时间,没有NPE,但你知道,我不能让一些事情依赖于此 不可预测的“相对较长的等待时间” 有人能给出解决方案吗?您不能将主页中定义的CSS规则应用于RichTextArea的内容。 您必须在
实际上,问题是RichTextBox在附加到 DOM,它的内部内容(html,body)没有生成,甚至我将这些行包装到 onload()方法,NPE有时会被抛出,但如果将它们包装到计时器中,则计划 一个相对较长的等待时间,没有NPE,但你知道,我不能让一些事情依赖于此 不可预测的“相对较长的等待时间”
有人能给出解决方案吗?您不能将主页中定义的CSS规则应用于RichTextArea的内容。 您必须在RichTextArea创建的iframe中包含样式 下面是一个具有内联样式的简单示例:
RichTextArea richTextArea = new RichTextArea();
richTextArea.setSize("200px", "200px");
richTextArea.setHTML("<html><head><style type=\"text/css\">h1 {color: red}</style></head><body><h1>Title</h1><p>content...</p></body></html>");
RootPanel.get().add(richTextArea);
RichTextArea RichTextArea=new RichTextArea();
设置大小(“200px”、“200px”);
setHTML(“h1{color:red}标题内容…”;
RootPanel.get().add(richTextArea);
您还可以使用外部css文件。设置为richTextEditor的html代码必须进行相应的调整。您能告诉我原因吗?我需要通过JSNI将剪切/粘贴侦听器注册到body元素,因此我确实需要操作body元素。按照您的解决方案,我仍然无法获取body元素,并且所有事件都不起作用
Element body = ((FrameElement) getElement().cast()).getContentDocument().getBody();
body.setClassName("richTextArea");
Scheduler.get().scheduleDeferred(new ScheduledCommand()
{
@Override
public void execute()
{
Element body = ((FrameElement) getElement().cast()).getContentDocument().getBody();
body.setClassName("richTextArea");
}
});
RichTextArea richTextArea = new RichTextArea();
richTextArea.setSize("200px", "200px");
richTextArea.setHTML("<html><head><style type=\"text/css\">h1 {color: red}</style></head><body><h1>Title</h1><p>content...</p></body></html>");
RootPanel.get().add(richTextArea);