Solved

Changing components in containers

Posted on 1997-04-28
2
164 Views
Last Modified: 2010-04-16
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
Comment
Question by:cardell
2 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1219942
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
 
LVL 1

Accepted Solution

by:
datadesign earned 50 total points
ID: 1219943
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question