is there a way to make widget based on subcomponents which are resized according to parent component size using "offsetHeight" properties to work in design view?
here is example code:
- Code: Select all
package com.mycompany.project.client;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
public class TestPanel extends Widget {
Element header;
Element body;
Element footer;
public TestPanel() {
setElement(DOM.createDiv());
DOM.setStyleAttribute(getElement(), "border", "1px solid #666666");
header = DOM.createDiv();
setText(header, "header");
DOM.appendChild(getElement(), header);
DOM.setStyleAttribute(header, "backgroundColor", "yellow");
body = DOM.createDiv();
setText(body, "body");
DOM.appendChild(getElement(), body);
DOM.setStyleAttribute(body, "backgroundColor", "red");
footer = DOM.createDiv();
setText(footer, "footer");
DOM.appendChild(getElement(), footer);
DOM.setStyleAttribute(footer, "backgroundColor", "yellow");
}
private void setText(Element element, String text) {
DOM.setInnerText(element, text);
}
/* @Override */
public void setHeight(String height) {
super.setHeight(height);
updateBodyHeight();
}
private void updateBodyHeight() {
int pHeight = getOffsetHeight();
int hHeight = DOM.getElementPropertyInt(header, "offsetHeight");
int fHeight = DOM.getElementPropertyInt(footer, "offsetHeight");
int bH = pHeight - hHeight - fHeight;
setText(header, pHeight + ":" + hHeight + ":" + fHeight + ":" + bH);
DOM.setStyleAttribute(body, "height", bH + "");
}
}
body content (red color) should be resized to fill parent content, header/footer are left as is,
this is like common Panel UI is modelled,
the required Designer view is inverted Spain flag colors (y/r/y) and it works in hosted mode but fails in design view when red area take all available height,
I could upload .zip-ped designer project but code just works without errors,
use in entry point:
- Code: Select all
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestPanelHeight implements EntryPoint {
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
final TestPanel testPanel = new TestPanel();
rootPanel.add(testPanel, 5, 5);
testPanel.setSize("320px", "240px");
}
}
regadrs,
Peter