Removing components in a window w/o affecting others.- AbsoluteLayout


I have this sub window which has an AbsoluteLayout layout. On the north side of it is a GridLayout and at the south side are 2 buttons. I have this List of GridLayouts which I dynamically add in the sub window to display it(at the north side). The only way I’m doing this right now to make sure a GridLayout is displayed is to remove every component in the sub window(GridLayout and 2 buttons) and add them again. This seems impractical but if I only remove the component at the north side which is the GridLayout and leave the other components on the south side(2 buttons), the next dynamic display/add of a GridLayout will cause to hide or unshow the buttons. I don’t know what exactly had happened why the 2 buttons wont show anymore.

But in an AbsoluteLayout, would it be possible to redisplay only a component and not all in a sub window? It’s impractical to remove all components and add them again just to redisplay one component in a window. Please help me, I’m might have missed something. Any help is greatly appreciated :wacko:

Sounds like either a bug in your program or a bug in the layout. You should really be able to just remove and add (or replace) one component and the layout should be updated automatically. If you post some code maybe somebody can figure out where the problem is.

Thanks for your feedback Artur, now I have an idea where to investigate more (my code).

Here’s the relevant code…

// main window
mainWin = new Window("Sugbu Sale");
mainWin.setContent(new GridLayout(SugbuSaleConst.MAIN_WIN_MAX_COLS, 
mainWin.setContent(new AbsoluteLayout());

// sub window
storeWin = new Window("There are "+dataBinder.getStoreDB().getNumOfOnSaleStores()+" ON-SALE stores today.");
storeWin.setContent(new AbsoluteLayout());

// sub window layout
storeWinLayout = (AbsoluteLayout)storeWin.getContent();

// here's how I redisplay the sub window/storeWin
public boolean redisplayStoreWin(int index){
		// remove store win components - "impractical"
		boolean success = true;
		GridLayout curStoreGrid = storeGrids.get(curStoreGridIndex);
                // here's how the 2 buttons are removed
		// add new store win components
		GridLayout newStoreGrid = storeGrids.get(index);
		String topPx = SugbuSaleConst.CSSPixels(SugbuSaleConst.STORE_GRID_START_Y);
		String leftPx = SugbuSaleConst.CSSPixels(SugbuSaleConst.STORE_GRID_START_X);

                // add back sub window components
		if(storeGrids.size() > 1)

		curStoreGridIndex = index;
		return success;

// here's how I enable/disable the 1st button (same for the other 2nd one, except 200px for "left")
public void enableNextStoresBtn(boolean enable){

			storeWinLayout.addComponent(nextStoresBtn, "top:5px; left:400px");

I’ve actually made a temporary workaround for this, by adding the buttons to a different sub window(outside the sub window above), so I can continue. I’m using “runo” themes by the way, but I assume themes don’t have anything to do with this problem. I hope the code above is helpful enough. Thanks! :rolleyes:

Hi! While using layout.removeComponent(new Label(“example”)); its not working. How to remove component from Layout permanently.

why do have these lines in your code:

mainWin.setContent(new GridLayout(SugbuSaleConst.MAIN_WIN_MAX_COLS, SugbuSaleConst.MAIN_WIN_MAX_ROWS)); mainWin.setContent(new AbsoluteLayout()); The first line should not do anything.

What are you trying to achieve with layout.removeComponent(new Label(“example”)); ?
It schould not work because you’re trying to remove a component from a layout which is not added to layout.

Hi. The given below method is used to removeComponent from Layout right.
void com.vaadin.ui.ComponentContainer.removeComponent(Component c)
Removes the component from this container.Parameters:c the component to be removed.

I want to remove the component from container and from memory space also. I want to recreate the comboboxes depends on the some other 2 comboboxes. So at the time wanna set the combobox title and datasources.[b]


[/size][font=Times New Roman]


Yes with removeComponent you can remove a Component from a Component Container like this:

VerticalLayout vl = new VerticalLayout(); Label lbl = new Label(); vl.addComponent(lbl);//adds the component vl.removeComponent(lbl);//removes the component This component however could be added to another Container afterwards. If you want to know something about removeComponent and Memory usage have a look at this

The combobox thing i didn’t quite understand, sry.