aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Hidden or Removed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Hidden or Removed" Watch "Hidden or Removed" New topic
Author

Hidden or Removed

Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
import java.awt.*;
public class TestFrame extends Frame
{
Button firstOne = new Button("One");
Button secondOne = new Button("Two");
public TestFrame()
{
add(firstOne,BorderLayout.NORTH);
add(secondOne,BorderLayout.NORTH);
setSize(400,400);
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
When its compiled Two comes out
But what happens to One
is it Removed or Hidden?
Jim Petersen
Ranch Hand

Joined: Jul 24, 2001
Posts: 241
Originally posted by Ragu Sivaraman:

add(firstOne,BorderLayout.NORTH);
add(secondOne,BorderLayout.NORTH);

Hi Ragu note when you use the BorderLayout you can add up to One component to any region(N,S,E,W, Center) so what happens is that when you attempt to and add another button to the to the North region you are effectively overwriting firstOne button with secondOne button only secondOne will be visible
All the best - Jim


- Jim Petersen <br />SCJP2<br />SCWCD<p>- but then again, I could be wrong...
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
AFAIK the component is removed from the Frame container... It would not make sense to hide it since you can achieve the same result with a CardLayout and furthermore you could run out of memory if you were to continuously add components to the Frame and never remove them... This is unlikely to create so much components but who knows ?!
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
If you look into the source of java/awt/BorderLayout.java in the method addLayoutComponent

where center, north, south, east and west are instances of Component, you may notice that those component are reassigned, which means the old one is not referenced anymore and may be gced soon...
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
BorderLayout tracks which components to keep in each of the 5 areas using 5 fields which hold a reference to the component that they should display. When the second Button is assigned to the NORTH area, the field replaced the reference to the first, so it is lost forever - not just covered up.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hidden or Removed