Thursday, July 8, 2010

Card Layout Manager  

0 comments

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);

}*/

What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



0 comments: to “ Card Layout Manager

Extension Factory Builder