• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWT

 
jeena jose
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following program...
import java.awt.*;
public class MyFrame
{
public static void main(String[] args)
{
Frame fr = new Frame();
Panel p = new Panel();
Button b1 = new Button("North");
p.add(b1);
Button b2 = new Button("South");
fr.add("North", p);
fr.add("South", b2);
fr.setSize(300,400);
fr.setVisible(true);
}
}
on resizing width of North will not change.why???
 
Sharada Kumaran
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The buttons are added to the panel using FlowLayout (the default layout for Panels). FlowLayout honors the preferred size of the component, and will not resize the component even when its container changes size. The panel is added to the Frame using BorderLayout. On resizing the Frame, the panel might get resized, but the button in the panel is not affected. Infact, that is the primay advantage of adding components to a Panel, as opposed to adding it directly to the Frame.
Hope I could clear your doubt.
Sharada
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic