Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 43027
76
  • 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: 22647
126
Eclipse IDE Spring VI Editor 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: 22647
126
Eclipse IDE Spring VI Editor 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.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic