• Post Reply Bookmark Topic Watch Topic
  • New Topic

add jpanel to jframe

 
Paru kutty
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,I want to know how to add jpanel to jframe .will this much in my code do?
JPanel jp=new jPanel();
jp.setSize(200,50);
jp.add(button1);//here i add components
jp.add(button2);
frame.setContentPane( BorderLayout.CENTER);
Am using Grid Bag layout...have already included the code before in this session,so I am not reposting it...thanks in advance
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried compiling that? I don't think so, or you'd have found out that "frame.setContentPane( BorderLayout.CENTER);" will not compile. This method takes a Container, not a String. Don't you mean "frame.setContentPane("jp);"?

Also, "jp.setSize(200,50);" may not work if the parent component's layout manager overrides the size. If the JPanel is your ContentPane I don't think it will cause any problems though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!