Solved

Changing components in containers

Posted on 1997-04-28
2
160 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changePi Challenge 15 75
topping3 challenge 14 48
Impossible to extract MSI from new JAVA releases 2 37
mockito example issue 8 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now