The Artima Developer Community
Sponsored Link

Java Answers Forum
Replace Panel

4 replies on 1 page. Most recent reply: Aug 31, 2005 4:35 AM by Will

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Replace Panel Posted: Aug 30, 2005 8:23 AM
Reply to this message Reply
Advertisement
Hi,

I'm looking for a simple method to replace a panel in a gui with a panel from another class. I can replace panels with other panels from the same class, but I'm really struggling with modifiers and things when I try to replace fom a different class.

If anyone could help me, or even explain where I might start looking, I'd be really grateful.


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Replace Panel Posted: Aug 30, 2005 11:15 PM
Reply to this message Reply
My suggestion would be to set your frame to have
a CardLayout. There is a Layout Manager in Java
that handles that I think its called CardLayout
(see Java API), you can code it to function just
like you are shuffling a deck of cards, what panel
you smack on the front of the deck will depend
totally on your code (That's just one way though).

Hope that helps.

Goodluck,
Spike

Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Re: Replace Panel Posted: Aug 31, 2005 1:56 AM
Reply to this message Reply
Thanks for the help Spike - I'd forgotten about CardLayout.

One question though - my current setup is a gridbaglayout with top, center and bottom panels (although the bottom panel is really obsolete). The top panel contains a JToolbar, so I'm not sure if this would work with a cardlayout unless I added the toolbar to each card (which I don't really want to do)?

One of the problems I seem to have when I try to replace the center panel is that the existing panel is not removing properly - even with repaint() and validate() methods, the new panel is superimposed over the old one, so my remove(centerPanel) method doesn't seem to be working.

Thanks again :)

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Replace Panel Posted: Aug 31, 2005 3:26 AM
Reply to this message Reply
Is it the same toolbar for each panel?
Then use CardLayout for the center panel and add your custom panels to this center panel.

Will

Posts: 20
Nickname: lofty
Registered: Mar, 2005

Re: Replace Panel Posted: Aug 31, 2005 4:35 AM
Reply to this message Reply
Yes it is the same - I hadn't thought about setting carlayout as the manager for a single panel - thanks for the help!

Flat View: This topic has 4 replies on 1 page
Topic: ActionMap Ctl Space Previous Topic   Next Topic Topic: JAva Application and JDBC Oracle 9i connection problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use