This week's giveaway is in the OCPJP forum.
We're giving away four copies of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) and have Paul Anilprem on-line!
See this thread for details.
Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic