simple first u add em. in case ur componets to be added are ,say JPanel then.. panel.add (chatPanel, "one"); panel.add (whiteboardPanel, "two"); then u add action listeners & then depending on the action command.. cardLayout.show(panel, "one"); cardLayout.show(panel, "two"); enjoy
Helmut, Ummm... you can't... but your program can keep track of this if it needs to. Can you give some code or at least a description of what you are trying to do? Thanks, -Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Dec 09, 2000
hi helmut correct me if i am wrong. cant u just have a globla variable :"String activeWindow" which is updated by getActionCommand() in that way activeWindow will contain the name of the window which is currently showing...
Joined: Feb 11, 2001
Originally posted by Nathan Pruett: Helmut, Ummm... you can't... but your program can keep track of this if it needs to. Can you give some code or at least a description of what you are trying to do? Thanks, -Nate
I do it until now by keeping track within my Code (Hashtable with String to Component, Buttons to select within CardLayout, ActionListener and get() on Hashtable). I thought it would be nice if there is a method like getComponentShowing() in the CardLayout. Thanks for answering
I agree it would be nice to have, and I spent some time myself looking while working of a previous project. In practice, Sun seem to have never been very keen on CardLayout, so it has never had much support or development.