• 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

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: 22802
131
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.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic