在codenameone中显示html文本

时间:2014-06-19 15:41:11

标签: codenameone

我想显示我作为字符串的html格式的文本。 WebBroswer组件是否支持此功能? 如果是,使用什么方法? 谢谢, SANKET

代码:

private void loadCourseDesc() {
    Container courseDescContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    NETextArea title = new NETextArea(AppState.current_Course.getTitle());
    title.setUIID("biggreylabel");
    courseDescContainer.addComponent(title);
    Container c1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
    Label l = new Label("Fees:" + AppState.current_Course.getFees());
    l.setUIID("mgreylabel");
    c1.addComponent(l);
    Label l1 = new Label("Completion Date:" + AppState.current_Course.getExpiryDate());
    l1.setUIID("mgreylabelLM");
    c1.addComponent(l1);
    courseDescContainer.addComponent(c1);
    WebBrowser wb = new WebBrowser(){

        @Override
        public void onLoad(String url) {
            super.onLoad(url); //To change body of generated methods, choose Tools | Templates.
            instance.forceRevalidate();
        }

    };
    wb.setScrollableY(true);
    System.out.println("::---" + AppState.current_Course.getDesc());

    wb.setPage(AppState.current_Course.getDesc(), "http://localhost/");
    courseDescContainer.addComponent(wb);
    replace(courseDescContainer);

替换代码:

private void replace(final Container c) {
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            instance.replaceAndWait(currentCentre, c, null);
            currentCentre = c;
            instance.forceRevalidate();
        }
    });

}

1 个答案:

答案 0 :(得分:1)

它通过将组件添加到容器中来支持它,设置HTML而不是URL只需使用setPage而不是setURL