• 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 (Marcus Green)

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was wondering why buttons will run from left to right along the top of the frame. I thought the buttons will stay at the button since the layout has been set to the south initially at line 12. Do i need a validate() to apply borderlayout follow by flowlayout? pleaseeeee help.
thanks, yuki
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); //12
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yuki,
The statement <code>setLayout(new FlowLayout())</code> effectively sets the layout manager for the current <code>CompLay</code> object; this replaces the original default layout of <code>BorderLayout</code>.
When the container is sized, the <code>FlowLayout</code> manager queries the container for a list of it's components; in this case, one, <code>Panel p</code> which it displays. The previous statement of <code>add("South",p)</code> has no meaning for the <code>FlowLayout</code>.
To see the results you expected, comment out <code>setLayout</code>. You do not need to <code>validate()</code>. The <code>Panel</code>'s default layout is <code>FlowLayout</code>
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Yuki Cho
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jane, i got it now!
-Yuki
 
brevity is the soul of wit - shakepeare. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic