Forums Register Login

Regarding CardLayout

+Pie Number of slices to send: Send
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;
}
});

 
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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 ]
Let me tell you a story about a man named Jed. He made this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1082 times.
Similar Threads
Refactoring: need help in finding bad smells
Problem with Text Fields
How to navigate between multiple GUI classes
no such method error
Problem clearing and resetting a JPanel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:09:56.