rainer
rainer

Reputation: 3411

Codename One refresh form

In my app I want to reload a form. Problem is that every time I reload the form, existing items persists on the screen and new ones are added subsequently.

There are, for example, two buttons: buttonOne and buttonTwo. Both inside a container. The container is added to the form.

When I reload the form, buttonOne and buttonTwo are added again to the already existing two buttons. When I reload again, buttons One and Two are four times on the screen.

I have tried:

form.removeAll();
containerButton.removeAll();
containerButton.remove();
form.repaint();
form.refreshTheme();

// reload the form 

channels (); 

// the class

public Form form = new Form(new BoxLayout(2));

public void channels() { 

   container.add (buttonOne).add(buttonTwo);
   form.add (containerButton);

}

This approach does not solve the issue. What am I missing?

Thanks in advance for any reply.

Upvotes: 2

Views: 779

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

Remove all would remove the components from the Container (in this case the form content pane) but won't remove them through the hierarchy.

Both:

form.repaint();
form.refreshTheme();

Are incorrect API's to use when changing the hierarchy. You need to use revalidate() or animateLayout().

"Reload" isn't a concept that exists in Codename One since the widgets are unaware of your data. A common fool proof trick is recreating the form from scratch and showing it.

Upvotes: 3

Related Questions