🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12679

Re: Changing panels within a frame

#12679
From: Matt Krevs
Date: Mon, 23 Nov 1998 00:00
57 lines
2975 bytes
A short term solution is to call validate() instead of repaint().

The best solution is to use CardLayout as your layout manager. You add all
panels to the frame and based on some criteria you call the show() method
within the CardLayout class.
Basically its like having many tab pages without the tabs.

Follow this link for an example on using CardLayout
http://java.sun.com/docs/books/tutorial/ui/swingLayout/card.html

Matt Stauffer wrote in message <3658C12C.DA95AA40@jmaca.com>...
>I'm having trouble displaying different panels within one frame.
>
>What I'm trying to do is display several screens of info (user makes one
>or two selections on each screen), very similar to say what happens when
>you install a program with InstallShield. What I want to do is have a
>frame with several panels. When I first create the frame I also create
>the first panel and display it on the frame. Once the user clicks the
>"Next >>" button I want to remove the first panel and then put the
>second panel in its place on the frame and trash the first panel (I
>figured this would be better then trashing the whole frame and creating
>a whole new frame).
>
>Here's the pertinent parts of the code (from the frame class):
>
>       // adding the first panel
>        this.getContentPane().add( introPanel, BorderLayout.CENTER );
>        . . .
>
>      // remove the first panel and replace it with the second
>      this.getContentPane().remove( introPanel );
>      introPanel = null;
>      projectPanel = new ProjectPanel( this );
>       this.getContentPane().add( projectPanel, BorderLayout.CENTER );
>       // I don't know if repaint is necessary but call it just to be
>safe.
>        repaint();
>
>What is currently happening is it displays the first panel properly,
>when I click the "Next >>" button it prints out the debugging message in
>my event handler and it appears to remove the first panel, but it
>doesn't display the second panel. It just shows an empty frame. If I
>display the second panel when I start up the program it displays
>properly so my two panels seem to be okay.
>
>I think I've done something similar to this with AWT before, but it
>doesn't seem to work for me now. Is there something else unique to Swing
>that I'm doing wrong here? Am I just missing something blatantly
>obvious, or just doing something incredibly stupid?
>
>Thanks for any help.
>
>--
>Matt Stauffer
>matts@jmaca.com
>
>
Technical Details
Message-ID: <73afqt$54t19@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3658C12C.DA95AA40@jmaca.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,facde98a621e3092
X-Google-Attributes: gid111d45,public
From: "Matt Krevs" <mattkrevs@flex.com.au>
Subject: Re: Changing panels within a frame
Date: 1998/11/23
Message-ID: <73afqt$54t19@forums.borland.com>
X-Deja-AN: 414649738
References: <3658C12C.DA95AA40@jmaca.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing