0
votes

I have a form in SWT where I have five different composites based on one parent composite.Each of the composite contains different widgets like a single textbox / a combo box / a combination of text and combo etc.

Now the problem is when I click on the button I want to change my third composite to carry a different widget keeping others static.Now I can't reload from the beginning as I want current values of the other widgets to be displayed.How can I fetch only that composite,dispose it and create a new widget in place of that.

Creating and hiding the widget is difficult to consider as it is dynamic to at what place we want to redraw.

Here is the snippet.

    formComposite=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout=new GridLayout(5,false);
    fromComposite.setLayout(formLayout)
    item.create(formComposite)  //Here item is the widget (combo/textbox/combination text/combo)

     formComposite1=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout1=new GridLayout(5,false);
    fromComposite1.setLayout(formLayout)
    item1.create(formComposite1))

  formComposite2=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout2=new GridLayout(5,false);
    fromComposite2.setLayout(formLayout)
    item2.create(formComposite2))

 formComposite3=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout3=new GridLayout(5,false);
    fromComposite3.setLayout(formLayout)
    item3.create(formComposite3))

 formComposite4=new Composite(parentComposite,SWT.BORDER_SOLID);
    formLayout4=new GridLayout(5,false);
    fromComposite4.setLayout(formLayout)
    item4.create(formComposite4))

Now how can I replace item3 with a different item to be created keeping others static in their place?

2
Note: BORDER_SOLID is not a valid style for a Composite. – greg-449

2 Answers

2
votes

Assuming you only have one child for each Composite you can just dispose of the existing control and add the new one and then redo the layout.

item.dispose();

item = new Combo(fromComposite, ... style);

formComposite.layout(true);

You may also have to call layout on the parentComposite.

0
votes

you could do this by using Control.moveAbove() and Control.moveBelow() methods

// create item3replacement
item3replacement.moveAbove(item3);
item3.dispose();
// call layout on parent when all is done

otherwise you will need to write your own Layout to do so. as you are using GridLayout this will be your starting point. you need to add a value for an position to GridData and process this in the GridLayout