Sunday, February 22, 2009

Card Layout Manager

One of the most complex Layout Manager is Card Layout manager.Using this manager you can create a stack of cards and flip from one layout to another.This type of organization is similar to tabbed dialogs.Card Layout provides following

Costructors
:-

public CardLayout(); //Constructor creates new CardLayout

public CardLayout(int hgap,int vgap);//Constructor creates a new card layout with specified horizontal and vertical gap.




To Create a Card Layout Manager with card layout manager object,you first create a parent panel to hold the cards .Then you create an object of the CardLayout class and set it as the layout manager of the panel.Finally ,you add each card to the layout by creating the component and adding the to the panel.

Following are the methods to switch between cards that are in stack of layout.

1.void first(Container parent) //Display first card
2.void last(Container parent) //Display last card
3.void next(Container parent) //Display next card
4.void previous(Container parent) //Display previous card
5.void first(Container parent,String name) //Display specified card

Example
code snippet:-

/*
CardLayout c1;
JPanel panel;
JButton jb 1;
cardlayout()
{
JFrame jf1=new JFrame("Card Layout demo");
JPanel panel=new JPanel();
JButton jb1=new JButton("Next Button>>");
JButton jb2=new JButton("Last Button>>");
CardLayout c1=new CardLayout();
panel.setLayout(c1);
panel.add("button1",jb1);
panel.add("button2",jb2);
jb1.addActionListener(this);
jb2.addActionListener(this);
jf1.getContentPane().add(panel);
jf1.setVisible(true);
jf1.setSize(200,200);
}
public void actionPerformed(ActionEvent ae)
{
c1.next(panel);

}*/

Other Layout Managers Links:-

Layout Manager Basics
Box Layout
Grid Layout
Border Layout
Flow Layout
GridBag Layout

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey(Read More about him) .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP