aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubts over layouts Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "doubts over layouts" Watch "doubts over layouts" New topic
Author

doubts over layouts

shilpa gupta
Greenhorn

Joined: Feb 09, 2001
Posts: 26
2]
A)
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 BorderLayout());
add(bSouth,BorderLayout.SOUTH);
add(bWest,BorderLayout.WEST);
add(bEast,BorderLayout.EAST);
add(bNorth,BorderLayout.NORTH);
add(bCenter);
setLayout(new FlowLayout());
validate();
pack();
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
B) 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();
}
}
first program gives buttons arrnged according to flowLayout
but the second one does not display any buttons.
Why?
Hima Mangal
Ranch Hand

Joined: Feb 25, 2001
Posts: 82
i guess that's because there can be only one layout manager for a container and once u specify a new layout manager over an old one.. the components need to be readded.. guess so...


Hima<BR>Sun Certified Java Programmer
puneet pruthi
Greenhorn

Joined: Feb 10, 2001
Posts: 14
Hi shilpa,
Abt the layouts,suppose u have initially borderlayout and u have added buttons to it,specifying flow or grid layout ,would override it and the components will b placed acc to the new layout.
but if u have flow layout and u give borderlayout afterwards,it wont override ,but give a completely new layoutwhich is blank.It will enclipse the previous layout with the components.
Why this happens ,i dont have a clue,i read it some where but no reasons were given.
Navin Narayan
Greenhorn

Joined: Jan 25, 2001
Posts: 25
Hi All,
The problem has been well explained by Jane Griscti. You can find it at the following link
http://www.javaranch.com/ubb/Forum24/HTML/006887.html
Navin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubts over layouts
 
Similar Threads
AWT FlowLayout to BorderLayout
java.awt BorderLayout and FlowLayout
Why the button doesn't appears in the Frame?
Why the button doesn't appear in th frame?
Layout