Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get the current JPanel in a CardLayout

843806Jan 4 2009 — edited Jan 5 2009
Hi,

is there any way to return the name of the current JPanel in a CardLayout JPanel?
I would like to compare if the first JPanel in the CardLayout equals the current one.
CardLayout cl = (CardLayout)(steps.getLayout());
        if(cl.first() == current JPanel in card layout)
            //some code
As a samle code, you can use Suns one: http://java.sun.com/docs/books/tutorial/uiswing/examples/layout/CardLayoutDemoProject/src/layout/CardLayoutDemo.java



EDIT:

I solved it with:
Component c[] = steps.getComponents();
        int i = 0;
            int j = c.length;
            while (i < j) {
               if (c[0].isVisible())
               {
                  // add what you want to do here
                  break;
               }
               else
                  i ++;
               }
But if there is any easier way to do this, I would be more than glad to know it.

Edited by: Roxxor on Jan 4, 2009 2:53 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2009
Added on Jan 4 2009
3 comments
1,071 views