Solved

Changing components in containers

Posted on 1997-04-28
2
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 265
Java syntax, or is it Selenium 6 62
dao vs facade design patterns 2 75
listing all the respondents to a twitter feed - Java 5 49
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…
Suggested Courses

751 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