Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Changing components in containers

I'm trying to add new elements to a frame, and get rid of the other elements that were there.  For instance an applet where I add(new Label("Hello")) ... now I want "Hello" to disappear and I want to add(new Label("Goodbye").

I thought that either clearAll() or some use of repaint() would do it, but I can't get it to clear and then add components.  I can't find any examples of doing this in my books....can anyone help me??


0
cardell
Asked:
cardell
1 Solution
 
jpk041897Commented:
For what its worth, they way I solved it is to call the components show(true/false) flag.

For Instance:

myLabelHi.show(false);
myLabelBye.show(true);

Its a bit messy when you have a lot of components but it soleves all sorts of programming problems.
0
 
datadesignCommented:
ok !
you added the components to the container, and when u want to remove them, you have to call .remove(Component) or removeAll()
 for example

public class Applet1 extends Applet
{
      public Panel panel = new Panel();
      public Label a = new Label("Hallo");
      public Label b = new Label("Bye");

       public Applet1()
      {
               super();
               this.add(panel);
               panel.add(a);
       }
.... some interaction

       {
                panel.remove(a);
                panel.add(b);
                panel.show();
        }

.... and so on
               
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now