aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Setting the size for a panel within a frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Setting the size for a panel within a frame" Watch "Setting the size for a panel within a frame" New topic
Author

Setting the size for a panel within a frame

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hello all,
I want to set the size for the panel within a frame. When i run the below i get a small pink panel with the buttons at the bottom of the frame, but i am not able to increase the size of the panel. i tried to add the line 14 but does not help.
Kindle help me.

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());
Line 14//p.setSize(300,300);
setSize(600,600);
setVisible(true);
}
}
thanks mala
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Try this,
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
setLayout(null);
add(p);
p.setBounds(100,100,300,300);
setSize(600,600);
setVisible(true);
--------
Note: if you are using a layout manager you can not control the panel's size using setSize() or setBounds()
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Setting the size for a panel within a frame