PDA

View Full Version : ContentPanel do not show on click of button



navi75
1 Aug 2009, 5:12 AM
I am using EXT-GWT2.01 and GWT1.7 and added two contentPanel into a HorizontalPanel.

ContentPanel one = new ContentPanel();
one.add(new Grid());

ContentPanel two = new ContentPanel();
two.add(new LabelField("text"));
two.hide();

HorizontalPanel hp = new HorizontalPanel();
hp.add(one);
hp.add(two);

Since i have hide the second contentPanel inorder to show only the first contentPanel initially.

Now on the click of the button on the toolbar, i want to hide the first contentPanel and show the second contentPanel which was hidden earlier.

on the click of the toggleButton

if(contentPanelone.isVisible()) {
one.hide();
two.show();
}

The problem is that the one contentPanel does hide but it did not show the second contentPanel on the call for two.show();

Can anyone help me on the same?

Arno.Nyhm
6 Aug 2009, 2:47 AM
i think you should provide a full working example which shows your error. i think is on other place in your code.

i try your situation and it works fine:


package org.yournamehere.client.forum.code.snippets;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class ForumThread367150 implements EntryPoint {

public void onModuleLoad() {
final ContentPanel one = new ContentPanel();
one.add(new LabelField("text one"));

final ContentPanel two = new ContentPanel();
two.add(new LabelField("text two"));
two.hide();

HorizontalPanel hp = new HorizontalPanel();
hp.add(one);
hp.add(two);
hp.add(new Button("click me", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {

// if (one.isVisible()) {
// one.hide();
// two.show();
// } else {
// one.show();
// two.hide();
// }

boolean isVisible = one.isVisible();
one.setVisible(!isVisible);
two.setVisible(isVisible);
}
}));

RootPanel.get().add(hp);
}
}

navi75
6 Aug 2009, 5:17 PM
Thanks for your response.

I have solved the issue with the help of Registry.set(obj) in the onModuleLoad and Registry.get(obj) to retrieve the main object which has all of the contentpanel objects and once i retrieve the main object with the help of Registry, i used getItemByItemId("Id") to retrieve the contentpanel object and then used the hide and show functions on the same.

Arno.Nyhm
10 Aug 2009, 3:59 AM
fine that you solve your issue.

but what im not understand why you need the Registry things. what is special with your case? can you give some example code.

navi75
11 Aug 2009, 3:06 PM
I used Registry to get the reference of the first contentpanel object which i need to hide and show the second content panel.

Arno.Nyhm
12 Aug 2009, 9:00 AM
so the problem was not that you can not hide the panels - so it was more the problem that you dont have a reference to this panel?

navi75
14 Aug 2009, 6:03 PM
Yes. The problem was How to get the reference of the two contentpanel objects.

Thanks.