Solved

Changing components in containers

Posted on 1997-04-28
2
163 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Server Faces parameter pass? 6 48
Java Loop 6 59
Tomcat: Unable to run tomcat service. 2 18
Java: How do I open the default windows program for a given file type 3 28
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

808 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