aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes HELLP! i cant get 2 JPanels to display without them sitting on the other! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "HELLP! i cant get 2 JPanels to display without them sitting on the other!" Watch "HELLP! i cant get 2 JPanels to display without them sitting on the other!" New topic
Author

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

Karis Brown
Ranch Hand

Joined: Nov 13, 2003
Posts: 33
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 ]

So Cold & So Outa Control
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Where is the "A3PizzaProgram" class? I don't see it anywhere in the code you posted...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Karis Brown
Ranch Hand

Joined: Nov 13, 2003
Posts: 33
It goes in the begining...here u go
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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

Joined: Nov 13, 2003
Posts: 33
would i have to do the same getContentPane for all my stuff in my other classes?
Karis Brown
Ranch Hand

Joined: Nov 13, 2003
Posts: 33
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

Joined: Nov 13, 2003
Posts: 33
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

Joined: Nov 13, 2003
Posts: 33
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HELLP! i cant get 2 JPanels to display without them sitting on the other!