• 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

Card Confusion

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a litle confused concerning the CardLayout manager. Many books show code where an anonymous instance to a Layout Manager is created. For example suppose F is an instance of a Frame. To set the layout manager to FlowLayout we could write:
setLayout(new FlowLayout());
And I have found some instances where this is done with the CardLayout manager. HOWEVER, since the actual methods for showing the panels belong to the instance of CardLayout and not the container component, writing:
setLayout(new CardLayout());
is entirely self defeating since we wouldn't be able to call the various methods for displaying the "cards", eg. first, prev, next ... etc.
Am I right here, and the books are wrong - or is it (more likely) the other way around?
Thanks in advance
Dan
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's possible to recover the layout manager later using the getLayout() method on whatever object you used setLayout() on. Of course, to access the CardLayout-specific methods, you need to cast the layout to CardLayout. I'd be more inclined to keep a copy in the first place, as you suggest.
 
Dan Temple
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes sense. Thanks for the help!
Dan
 
Aaaaaand ... we're on the march. Stylin. Get with it 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