Hi John,
1) ScrollPanel's usually require that you set a fixed height for them
otherwise they tend to just grow to accommodate their contents. Either
you use a fixed height that always remains the same, or you can use a
WindowResizeListener and a DeferredCommand to calculate their size
relative to the client window height. This has the advantage that the
height of the ScrollPanel will be recalculated if the user changes the
their browser window size.
2) It is useful to use HorizontalPanel's setCellWidth(),
setCellHeight() etc to get the effects you want. In this example I've
set the width of helloPanel fixed at 10ems, and set the cell width for
the logScrollPanel to 100% so it takes up all remaining width in the
client area. But you can also set percentages for these cell widths.
regards
gregor
public class SandBox implements EntryPoint, WindowResizeListener {
HorizontalPanel hPanel = new HorizontalPanel();
VerticalPanel helloPanel = new VerticalPanel();
VerticalPanel logPanel = new VerticalPanel();
ScrollPanel logScrollPanel = new ScrollPanel();
public void onModuleLoad() {
helloPanel.add(new Label("Hello"));
helloPanel.setBorderWidth(1);
hPanel.add(helloPanel);
hPanel.add(logScrollPanel);
logScrollPanel.add(logPanel);
logPanel.setBorderWidth(1);
hPanel.setWidth("100%");
// fixed helloPanel width option
helloPanel.setWidth("10em");
hPanel.setCellWidth(logScrollPanel,"100%");
// percentage helloPanel width option
//hPanel.setCellWidth(helloPanel,"20%");
//hPanel.setCellWidth(logScrollPanel,"80%");
RootPanel.get().add(hPanel);
Window.addWindowResizeListener(this);
DeferredCommand.addCommand(new Command() {
public void execute() {
onWindowResized(Window.getClientWidth(),
Window.getClientHeight());
}
});
for (int i = 0; i < 50; i++) {
log("test msg, i=" + i);
}
}
public void log(String msg) {
logPanel.add(new Label(msg));
}
public void onWindowResized(int width, int height) {
// if you e.g. put a header in you would need to
// resize the ScrollPanel relative to its own top.
// if you e.g. had a footer below it you would need
// to adjust for that too
int scrollerHeight = height
- logScrollPanel.getAbsoluteTop();
if (scrollerHeight < 1) scrollerHeight = 1;
logScrollPanel.setHeight("" + scrollerHeight);