wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes CardLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "CardLayout" Watch "CardLayout" New topic
Author

CardLayout

Helmut Lerch
Ranch Hand

Joined: Feb 11, 2001
Posts: 48
Hy all,
how can I get the active (showing) Component when using a CardLayout?
Thanks
Stanley George
Ranch Hand

Joined: Dec 09, 2000
Posts: 55
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Stanley George
Ranch Hand

Joined: Dec 09, 2000
Posts: 55
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...
Helmut Lerch
Ranch Hand

Joined: Feb 11, 2001
Posts: 48
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
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CardLayout
 
Similar Threads
Back Forward in java application
Redirecting of one frame to another frame
Simple multi piece applet GUI using Swing
JPanel exactly over another JPanel
CardLayout- how to deal with it?