• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

border layout

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consider the code below
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new FlowLayout());
add(bNorth);
add(bSouth);
add(bWest);
add(bEast);
add(bCenter);
setLayout(new BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
Will compile and run cleanly, but no component is visible.
I thought last button added will appear in the centre of the frame but why nothing is visible in the frame.
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Poornima,
After u changed the layout from FlowLayout to Borderlayout, U will have to "explicitly add the components again" to the new layout for it to appear.
But the opposite is not true. Means Frame has BorderLayout as its default layout. If u add items to the frame & then change it to a differnt layout. The components still appear. Without the need to explicitly add them to the new layout.
Hope I made sense.
Aruna
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Poornima,
First time the Frame has set with FlowLayout manager,new instance, and all the buttons are added to this instance of LayoutManager. And when the layout manager is reset with new instance of BorderLayout and since no components are added to it nowthing will be displayed. It's over writing the previous layout manger.
 
poornima viswa
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankx Aru and Sivaram
 
reply
    Bookmark Topic Watch Topic
  • New Topic