This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to use CardLayout Manager  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I want:
when i click on one of the radio buttons (in the west panel), i want the center panel to display one of 3 cards. problem is, i can't seem to pull it off!
here's the code for that particular tab and the action listener method for it:

thanks in advance!
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create some panel with a gridlayout (or layout of your choice)
create the 3 buttons, assign action listeners to them and add to the panel.

create ANOTHER panel ('cardPanel') and assign it with a CardLayout
Create 3 more different panels (you can add whatever components to these or make them whatever colours you want to distinguish them).

add your 3 unique panels to 'cardPanel' with the following
cardPanel.add(panel1,"panel1Identifier");
cardPanel.add(panel2,"panel2Identifier");
cardPanel.add(panel3,"panel3Identifier");

in each of your 3 action listeners for the 3 buttons do the following to call the appropriate form.
CardLayout cLay = cardPanel.getLayout();
cLay.show(cardPanel,"panel1Identifier");

keep in mind that you have to substitute the correct string identifier for the appropriate panel..
my method names might not be 100% correct (doing this quickly) , but you should be able to get the idea.
NOTE that with the show() method you are calling it on the layout manager and then giving the parent container as a parameter.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!