Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CardLayout problems  RSS feed

 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd override the getPreferredSize, getMinimumSize and getMaximumSize methods as appropriate; especially getPreferredSize.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Joonas Järvinen
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!