Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Keeping same window, but displaying new content?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Keeping same window, but displaying new content?

    Hello there,

    I'm still a newbie when it comes to Java, and I've just been learning about Swing. I was wondering how you could do this:

    Show a Start button and a picture, then, when the button is pressed, the picture and button disappear and a new set of buttons appear, almost like a new page on the same window?

    How can I do that?

    Thanks,

    Alex.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Keeping same window, but displaying new content?

    One way would be to use the Container class's remove and add methods.
    Another would be to use CardLayout.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Keeping same window, but displaying new content?

    Could you possibly explain this Container you mentioned. Sorry about this.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Keeping same window, but displaying new content?

    Container is a java SE class. See the API doc:
    Java Platform SE 6
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Keeping same window, but displaying new content?

    Please could you give a quick example? That website isn't very clear.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Keeping same window, but displaying new content?

    to remove all the components in a container, get a reference to the container and call the removeAll() method:
    refToContainer.removeAll();

    To remove a specific component:
    refToContainer.remove(refToComponent);
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    RedCloudTsunami (August 4th, 2012)

  8. #7
    Junior Member
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Keeping same window, but displaying new content?

    Many thanks! :-)

Similar Threads

  1. [SOLVED] Keeping Track
    By Nuggets in forum Loops & Control Statements
    Replies: 2
    Last Post: April 15th, 2012, 05:37 PM
  2. Replies: 1
    Last Post: December 17th, 2011, 03:32 AM
  3. [SOLVED] Help with keeping the gui one size
    By derekxec in forum AWT / Java Swing
    Replies: 3
    Last Post: July 27th, 2011, 02:43 PM
  4. keeping a tally
    By Neo in forum Java Theory & Questions
    Replies: 3
    Last Post: February 3rd, 2011, 06:36 AM
  5. Keeping Variable Values
    By The_Mexican in forum Java Theory & Questions
    Replies: 6
    Last Post: November 27th, 2010, 04:02 PM