tags:

views:

54

answers:

6

Hi,

I have a couple of composite widgets which all have dymaincally sizing object within them.

When I instantiate a composite widget I would like it to fill its container as a percentage, say 80% for example.

Each of the objects within the widget will grow to fit inside the composite regardless of composites size but the composite itself wont grow as a percentage of its container.

Is this even possible? I have tried the .setWidth() method but this won't recognise a % asd an argument.

+1  A: 

Ofcourse it is possible.Composite setWidth() method recognizes % also.Can you give me the sample code you are using? Make sure that calling of setWidth() method must be after the initwidget() call of your composite.try like this

public class Widget1 extends Composite{
 private VerticaPanel panel=new VerticalPanel();
 public Widget1(){
   initWidget(panel);
   setWidth("80%");
   panel.add(new Widget2());
  }
} 

public class Widget2 extends Composite{
 private VerticaPanel panel=new VerticalPanel();
 public Widget2(){
   initWidget(panel);
   setWidth("100%");
  }
}
BlackPanther
A: 

I am not setting the size within the composite widget class.

I have a calling class that instantiates the composite widget and then calls the setWidth() method on the new object.

I will try out your method and if it works then apply it to my problem. I will post again once I have some more information.

Thankyou for your help :-)

A: 

Here is my test composite class:

 **class CompositePane extends Composite {
//Define a panel that contains everything
private VerticalPanel compositePanel = new VerticalPanel();
private Button button1 = new Button("Button1");


public CompositePane(){//Start StatusPane constructor

 compositePanel.add(button1);
 initWidget(compositePanel);
 setWidth("100%");
 addStyleName("compositePanel");

}//End of StatusPane constructor


}//End of StatusPane class**

Here is my style attached to this object that shows the edges of the composite object:

 .compositePanel{

 **border: 5px solid black;

}**

When using a set value of pixels the border expands as expected.

When using 100%, it sit tightly around the button, where I need it to touch the outside edge of its container.

A: 

Hi,

Just tried your example by creating your two clases and calling widget1 from an onModuleLoad() method and it works.

I will carry on digging to see what I am doing wrong.

Once again thanks for your help.

A: 

Thanks.Where you are adding this CompositePanel. CompositePanel.setWidth("100%") method makes this compositePanel to use it parents 100% width.So in your case its parent width is less.Try the following example .You will understand that what to do in your code.Now borders width will be 800px.

VerticalPanel parentPanel=new VerticalPanel();
parentPanel.setWidth("800");
parentPanel.add(new CompositePanel());
RootPanel.get().add(parentPanel);
BlackPanther
A: 

I've Got it!

I have seen it working and now know that its possible! Thank you very much for poiting me in the right direction, its very much appreciated.