Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting the size for a panel within a frame

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic