Steve
Steve
Steve
Shady Sback wrote:Ok i will definitely try it out now. Just before i do, if the second component removes the first surely the position should change since the second has completely different coordinates to the first instance ?
Steve
Steve
Steve Luke wrote:I don't remember... I think the default layout for a JPanel is FlowLayout. You will definitely see two balls, but they will either be next to each other (horizontal flow) or one on top of the other (vertical flow). I think the best way to get absolute positioning is to pass null as the LayoutManager. But it has been a while since I played with GUI stuff.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
I think the best way to get absolute positioning is to pass null as the LayoutManager.
Tony Docherty wrote:
I think the best way to get absolute positioning is to pass null as the LayoutManager.
Yes, if you call setLayout(null) it removes any existing LayoutManager and it's then entirely up to you to control the size and location of all child components. Remember you will no longer have auto-handling of scenarios such as the component's size changing so you may want/need to add a listener to handle cases such as this.
Rob Spoor wrote:One word of advice - drop the Thread and Runnable. All it does is start a Swing timer which already does what you want.
Steve
Steve Luke wrote:Did you define the size of the component as well (another function normally influenced by the layout manager)?
I tried to use setLayout(null) but no components showed on the frame
Stevie Shorey wrote:
Rob Spoor wrote:One word of advice - drop the Thread and Runnable. All it does is start a Swing timer which already does what you want.
Appreciate it but this is simply a learning exercise for me as my actual program needs to make hundreds of bouncing balls each controlled by their own runnables. This is just a simpler version of it !!
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
By Overriding the paintcomponent do you simply mean i should call the repaint() method ?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |