tags:

views:

1678

answers:

3
+2  A: 

Use a border layout instead:

frame.getContentPane().setLayout(new BorderLayout());
BallCanvas ballCanvas = new BallCanvas();
frame.getContentPane().add(ballCanvas, BorderLayout.CENTER);            
frame.getContentPane().add(controlPanel, BorderLayout.SOUTH);

Also get rid of setPreferredSize() in favor of frame.setSize() to set the initial size of the display.

Dave Ray
do you have any other suggestions? I've changed it to a BorderLayout, and the canvas still retains it's original size after resizing. Also, check my edit
Simucal
@Simucal: Are you sure you put the ballCanvas in the CENTER?
Software Monkey
@SoftwareMonkey, Yes, see my edit. My code definitely has the canvas positioned in BorderLayout.CENTER.
Simucal
+1  A: 

If you followed Dave's advice, esp. putting the ballCanvas in the CENTER, then you must be setting a maximum size for ballCanvas.

Software Monkey
+1  A: 

Perhaps, the layout manager is just attempting to honor your preferred size.

I would:

A) remove the preferred just to see what happens ( not a very good idea anyway )

or

B) not use canvas in first place but JComponent. After all Canvas is AWT component, and I not pretty sure how they work as today anyway. JComponent is a light weight component and since you're using a JComponent as container they would... mmhhh work better together?

Gee.. I'm giving voodoo programming suggestions now. Better get to work.

C) What have always worked for me. Make an small proof of concept, by adding step by step the stuff in my code. Start with empty canvas, then add the preffered size, then etc. etc. Chances are, the bug is on the paint method :P

Good luck.

:)

OscarRyz
Thanks for the tips Oscar
Simucal