Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding CardLayout  RSS feed

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I know that in card layout we can add different cards and switch between them.
Now i have add buttons as first, last, next and previous. And i am able to do so by using this buttons.Now what i need is to get a card directly on clicking a button say xyz. Imagine you have 15 cards and you need to get the 7th card on clicking the xyz button how to do it. Please some body help me.
The code i used for first and last button is as follows for card layout with 4 cards.

This is for first button

firstb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
cl.first(panel);
currcard=1;
}
});

This is for last button

firstb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
cl.last(panel);
currcard=4;
}
});
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you're looking at using the show( ) method of the CardLayout, which you can find in the API here.

It takes two parameters, the first being the name of the component that is implementing the CardLayout which for you appears to be the "panel" object, and the second parameter is a String which matches the String used when you inserted your desired card component onto panel. The trick here is to retrieve this String, and that will depend on your program. One way is to create a simple array or arraylist to hold these Strings and simply retrieve the seventh item in the ArrayList (or array).
[ June 07, 2008: Message edited by: pete stein ]
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your help its working now. But i have one more problem.
I want to add a image to a panel which can cover upto 75% of its length. I already have some text fields above. I want to add image on same panel but below the text fields. So please any body can help.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by adeeb alexander:
..But i have one more problem.


Would you please start a new thread for every new topic? Usually people scroll through the thread list, reading the subject line for topics of interest. Having multiple topics in the same thread makes it difficult for them.
[ June 09, 2008: Message edited by: Maneesh Godbole ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!