• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

add jpanel to jframe

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22855
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic