Allocating space on a Frame for a Jpanel?

Give a preferredsize to your components. Use setPreferredSize to give them dimensions.

Give a preferredsize to your components. Use setPreferredSize to give them dimensions. Then , before calling setVisible( true ) on your JFrame, use the method pack().

It will pack the JFrame and give enough space to ensure every component's preferredsize will be respected (if possible). Regards, Stéphane.

– Snicolas Jun 13 at 17:33 many reasons, one tecnical is that setXXSize short-circuits each and every internal efforts to find a reasonable size based on current state. A more general is that returning reasonable size hints is the inherent responsibility of a component: the general rule is to never interfere with such responsibilities from the outside – kleopatra Jun 13 at 17:49 I believe you'r right, it's better for reusability to override getPreferredSize. Nevertheless, I often you setPreferredSize and never get any side-effects or messing any framework.

So it's a working work-around when you don't look for something that is really reusable accross multiple apps. – Snicolas Jun 13 at 17:51 looks like you never had to clean up layout mess caused by setXXSize ;) – kleopatra Jun 13 at 21:30.

Agree with giving the JPanels preferred sizes either with setPreferredSize or getPreferredSize if you are overriding the JPanel, but just as important, don't set the size of the JFrame but rather let its components set its best size. As Snicolas mentions, the pack() method will take care of this for you.

1 for setXXSize, +1 for a custom implementation of getXXSize – kleopatra Jun 13 at 9:38.

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