I'am trying to build a program that uses CardLayout and multiple JPanels. The problem I'am having is with JPanel sizes. How do I specify these component sizes? As far I'am aware of. SetSize() cannot be used when specifying component sizes. So what should I use to size them as I want?
I propably will have more problems coming with this. But lets go one at the time.
Ulf Dittmer wrote:You'd override the getPreferredSize, getMinimumSize and getMaximumSize methods as appropriate; especially getPreferredSize.
You don't need to override getPreferredSize(); once you call setPreferredSize, that will be the new preferred size. You can reset it to the automatically calculated version again by calling setPreferredSize(null).
If I want to set my panels size so it wont change no matter what. Do I have to set min, pref and max size or is there any more 'handy' way of doing it?
Just about any layout manager ignores a manually set size but use the preferred, minimum and maximum sizes instead. Therefore, you will need to use those.