• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Layout Managers

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
add("South",p);
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
This will layout the components at the top of the frame since the Layout is set to Flow Layout.
But somewhere I read that when setting the layout after some components have been layed out, will change the layout for the future components and not for the components that are already layed, According to that rule, dont you think that the buttons should be at the bottom and any new comp after that setLayout should get FlowLayout
Can someone clarify?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FlowLayoutManager is the default for Panels and Applets. It was there before you stated it.
 
Milind Deodhar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that, but the question is that once the components are added to frame which has default borderlayout, the components should remain and should not take flowlayout becasue it was changed afterwards
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Milind, buttons are added to the panel(flow layout), then Panel is added to the frame. Hope this is clear
Thanx
Vidya
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think his question is something else i have seen two ques like this in abhilash "s exam there he said in explanation that whenever we setvisible the components layout manager present at that time will rule .
So even if you are doing setLayout(new flowlayout())
in the constructor of frame after ading components o flowlayout
THEN AGAIN SETTING SETLAYOUT(new BorderLayOut());
nothing will be visible.
try this
Bi
Anurudh gupta
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic