Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELLP! i cant get 2 JPanels to display without them sitting on the other!

 
Karis Brown
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically the error I get is, "Do not use A3PizzaProgram.add() use A3PizzaProgram.getContentPane().add() instead"
I thought i was meant to use setContentPane("panelname") in the class for it to show up? And if I dont use two classes, and I put them in one, i cant get the 2 panels to show next to each other. They kind of sit on top of the other. I know its something to do with the "setContentPane()"
This is not all of the code but the code where I am using the Swing stuff.

.....

Also how can I incorporate this thread code
It dont seem to work, with two classes. i know there is a work around.
[ March 30, 2004: Message edited by: Karis Brown ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the "A3PizzaProgram" class? I don't see it anywhere in the code you posted...
 
Karis Brown
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It goes in the begining...here u go
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just like JFrame, JApplet is a top-level component, so you have to add things to the content pane instead of directly to the applet itself.

In the init() method of A3PizzaProgram you should have something like this (you may want to change the layout around a bit though... GridLayout just lines components up giving each one equal space):

 
Karis Brown
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would i have to do the same getContentPane for all my stuff in my other classes?
 
Karis Brown
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is driving me nutz! i got to hand this in today!
why is the pSc class not wshowing up on the screen applet, only the stuff in the public class A3Pizza shows. and my pIc will not compile anymore since this getContentPane thing.
 
Karis Brown
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please all help would be grateful for!, cant get my head roud why this cant compile let alone work!
my pIc class wont compile and my pSc does not even appear.
 
Karis Brown
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont worry about it, i decided not to do it in two seperate classes, makes things to complicated, however it would have made my calculations more easier and less coding.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic