Project

General

Profile

Actions

Support #2219

open

Please help me: Image isn't displayed

Added by Anonymous over 10 years ago. Updated over 10 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
09/17/2013
Due date:
% Done:

0%

Estimated time:

Description

I download the hello programme from http://www.webtoolkit.eu/jwt/examples/ , and changed it . But the image is NOT displayed.

How to display the image? Please help me.

The HelloMain.java source:

public class HelloMain extends WtServlet {

private static final long serialVersionUID = 1L;

public HelloMain() {

super();

}

@Override

public WApplication createApplication(WEnvironment env) {

/*

  • You could read information from the environment to decide whether the
  • user has permission to start a new application
    */
    return new HelloApplication(env);
    }
    }

//------------------------------------------------------------------

The HelloApplication.java source

public class HelloApplication extends WApplication {

public HelloApplication(WEnvironment env) {

super(env);

getRoot().addWidget(new WImage(new WLink("icons/wt_powered.jpg")));

getRoot().addWidget(new WText("yeah Your name, please ---0po0 ? "));

final WLineEdit nameEdit = new WLineEdit(getRoot());

nameEdit.setFocus();

WAnchor anchor = new WAnchor(new WLink(http://www.webtoolkit.eu/"), "Wt");

anchor.setTarget(AnchorTarget.TargetNewWindow);

WImage image = new WImage(new WLink("icons/emweb.jpg\"), anchor);

getRoot().addWidget(image);

WPushButton button = new WPushButton("yeah Greet me.", getRoot());

button.setMargin(5, Side.Left);

getRoot().addWidget(new WBreak());

final WText greeting = new WText(getRoot());

button.clicked().addListener(this, new Signal.Listener() {

public void trigger() {

greeting.setText("yeah Hello many many there, " + nameEdit.getText());

}

});

}

}

Actions #1

Updated by Wim Dumon over 10 years ago

  • Status changed from New to Feedback

(weird, I thought I answered this already)

In essence, widgets that are not in the widget tree will never be shown on screen. Adding widgets to the widget tree is done by either passing the parent as a parameter at the constructor, or by calleing parent.addWidget(). In your example, the WAnchor is never added to the widget tree, the image is first a child of the WAnchor (it's passed as 'parent' parameter in the WAnchor constructor) and then reparented at the root of the widget tree. If you want a anchored image, you can drop the line getRoot().addWidget(image);, since the image is already in the widget tree, and add the anchor instead to the root.

Most likely the image is not shown because the browser's request to fetch it (icons/emweb.jpg) returns an error (404 or something else). Check that your servlet container is configured correctly to send requests to icons/... to a folder that contains the images.

BR,

Wim.

Actions

Also available in: Atom PDF