• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

CardLayout problems

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd override the getPreferredSize, getMinimumSize and getMaximumSize methods as appropriate; especially getPreferredSize.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic