• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic