Read JFrame size from JPanel?

You can either pass the frame itself to the panel constructor and later query the size, or you might use getParent() which should return the direct parent of the panel. In that case it might be necessary to move further up the hierarchy until you reach the frame.

You can either pass the frame itself to the panel constructor and later query the size, or you might use getParent() which should return the direct parent of the panel. In that case it might be necessary to move further up the hierarchy until you reach the frame. Edit: depending on what you want to achieve, I'd suggest you first try and use Andrew's suggestions and use layout managers.

You should use the parent's size directly only if the layout manager doens't provide the functionality you need (note that the way that functionality is provided might be different than what you expect).

GetParent() worked like a treat :) – Brogrammer Sep 20 at 11:21.

Use a layout (or layouts). Then it won't be necessary to know the size of the parent container. See Laying Out Components Within a Container for details.

Update 1 How to make this dynamic so it updates continuously? The layouts will update the sizes and positions of components automatically. For custom painting, simply call Container.getSize() at time of paintComponent().

Update 2 However purpose of knowing frame size is to scale down my Lines and Arcs of RoadPanel In case I was not clear enough above: For custom painting, simply call Container.getSize() at time of paintComponent(). In this instance, the Container would be RoadPanel. Incidentally, this will work correctly irrespective of: RoadPanel having a Border.

Not being in a Frame or not being the root component.

For correct direction +1 – mKorbel Sep 20 at 11:22 Correct, However purpose of knowing frame size is to scale down my Lines and Arcs of RoadPanel :) But I didn't wanted scale up though. So now I can check if frame size is less than my path. GetBounds2D than repaint all arc and fit into visible area.

But when you scale up it should remain same and can be zoomed in by manually using zoom button :) – Brogrammer Sep 20 at 11:25 by using proper LayoutManager you'll never care about ... – mKorbel Sep 20 at 11:30 @mKorbel, Could you please tell me a LayoutManager, That can save me this extra coding? – Brogrammer Sep 20 at 11:33 See my Update 2 – Andrew Thompson Sep 20 at 11:43.

1, Thanks perfectly, What I wanted accepting Thomas's answer as he wrote it first lol :) – Brogrammer Sep 20 at 11:22.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions