Wednesday, 7 September 2011

No layout manager and componentResized

Swing does confuse me. It's probably me, not Swing I hasten to add. So I have no layout manager because none of the preset ones work for music staff elements, and writing one looks incredibly complex, especially if you want to reference all the components in the array that you want to lay out.

So I though no problem, no layout manager, implement the ComponentListener interface and when we're resized go figure out what that means to the staff elements contained. Works well, except for when the object is created - as it's created and it's size initially set, it's not technically resizing so no resize event. Means you end up with a component full of mush or empty on first paint, you then need to move it or lose focus and regain - all of those cause a resize event - inconsistent nonsense to me!

So it's been resolved by overriding setBounds(x,y,width,height), which now calls the super, then lays out the contents the way we want. Tracing shows we call setBounds before a repaint so it now all works the way it should. Waste of a couple of hours figuring that out though - or an investment of a couple of hours, that's the right way to think about it isn't it :)

No comments:

Post a Comment