PDA

View Full Version : Compare and set panel height



cupakob
3 Feb 2010, 5:16 AM
I have a horizontal panel, which contains two vertical panels.

I want to compare the height of the two vertical panels and to set a new height value for the smaller panel. I try it this way:



// Create box "Prüfung"
final VerticalPanel boxPruefung = addBoxPruefung();
boxPruefung.addStyleName("right-margin-spacer");

// Create box "Ansprechperson"
final VerticalPanel boxContactPerson = addBoxContactPerson();

int boxPruefungHeight = boxPruefung.getHeight();
int boxContactPersonHeight = boxContactPerson.getHeight();

if (boxPruefungHeight < boxContactPersonHeight) {
boxPruefung.setHeight(boxContactPersonHeight);
} else if (boxPruefungHeight > boxContactPersonHeight) {
boxContactPerson.setHeight(boxPruefungHeight);
}
I get following error:



java.lang.AssertionError: Method must be called after the component is rendered
I've tried to place the compare fragment at the end ot the method, but doesn't work. In my onModuleLoad() i just call some methods, so i'm not sure, where exactly to place this fragment.

micgala
3 Feb 2010, 7:57 AM
Try this:



@Override
protected void onRender(com.google.gwt.user.client.Element parent, int pos) {
super.onRender(parent, pos);

//put your fragment here
}


Regards,
Michel.

cupakob
3 Feb 2010, 11:16 PM
i don't have not any onRender() method....i have the onModuleLoad(), which calls another five methods. Each this five methods have at the end something like:


RootPanel.get("widgetId").add(pruefPanel);so i don't need any onRender(). Is my approach wrong?

micgala
4 Feb 2010, 12:32 AM
java.lang.AssertionError: Method must be called after the component is rendered

Your piece of code must be called after the component is rendered... you have to make sure of that...

So, you need to override the onRender method in your parent container... and put the piece of code inside the onRender method....

Or you need to add a Events.Render listener to your parent container...

cupakob
4 Feb 2010, 12:33 AM
okay, thanks....I'll try it.

cupakob
10 Mar 2010, 1:30 AM
i made some changes in my project and now i have my widgets. The problem is, that i still can't get the hight of the box, but now there isn't any error message. I just get empty page im browser and that's all....here part of my code:



public class FachadministratorenWidget extends LayoutContainer {
private VerticalPanel boxPanel;
private Label title;
private VerticalPanel contentBox;
private HorizontalPanel titlePanel;
private List<String> adminList;

/**
* Default constructor
*/
public FachadministratorenWidget() {
super();

// Initialize vars
init();

// Style the ui elements
style();

this.add(boxPanel);
}


/**
* Initialize vars
*/
private void init() {

adminList = buildAdminFullName(getAdminFirstNames(), getAdminLastNames());

// Create the box
boxPanel = Utilities.createBox(503, 205);

System.out.println("\n\n\n" + boxPanel.getHeight());

// Create panel for the title
titlePanel = new HorizontalPanel();

// Create title
title = Utilities.setBoxTitle("Fachadministratoren");

// Create panel for the content
contentBox = new VerticalPanel();

for(int i=0; i < adminList.size(); i++) {
HorizontalPanel row = new HorizontalPanel();
row.setPixelSize(481, 31);
row.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
row.setStyleName("left-margin-double-spacer right-margin-double-spacer");

Label adminName = new Label(adminList.get(i));
adminName.addStyleName("left-margin-double-spacer");

row.add(adminName);

if (i%2==1) {
row.setStyleName("selected-row-background left-margin-double-spacer");
}

contentBox.add(row);
}
}

/**
* Style ui elemens.
*/
private void style() {
// Set background for the title
title.setStyleName("label-size-491 box_title");

// Add title to panel
titlePanel.add(title);

// Set size
// TODO Remove size if content added
contentBox.setSize(430, 150);

// Add title and content to the box
boxPanel.add(titlePanel);
boxPanel.add(contentBox);
}


If i comment following row:


System.out.println("\n\n\n" + boxPanel.getHeight());

its working again.

My idea was to implement getter and setter for the hight in this widget, which i can use from the parent widget (with the "addListener(Events.Render...") . For that here must be possible to make something like


setHeight(boxPanel.getHeight());

Is my approach corrent? Can someone help me to solve the problem?