• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Hidden or Removed  RSS feed

 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Valentin Crettaz
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!