Applet Events

Posted on 1999-01-25
Medium Priority
Last Modified: 2010-05-18
I need to change the panel in BorderLayout.CENTER when the next button in BorderLayout.SOUTH is pressed.  Is there a way to update one panel in a layout using the events?  How do I do it?  

Question by:willpd
  • 2
LVL 16

Expert Comment

ID: 1234627
there is no problem updating whatever you wand based on some user actions.

please be more specific.

Author Comment

ID: 1234628
When the action is captured, how do I change the panel?  

For example:

public void actionPerformed(ActionEvent e)
    String Label = (String) e.getActionCommand();
    if (Label.equals("Next"))


Can you give me a code sample of how I would change the panel in the CENTER at that point?


Accepted Solution

sailwind earned 400 total points
ID: 1234629
The implementation would more or less depend on what you have
in the center. The easiest thing to do is to remove the original
panel and add the new one. If you have an image in the middle,
then you might want to just switch the image without using a
new panel. At any rate, let's assume you have something like:

JPanel centerPane = new JPanel();
JPanel southPane = new Japenl();
JPanel replacementPane = new JPanel();

JPanel mainDisplay = new JPanel();
mainDisplay.setLayout(new BorderLayout());
mainDisplay.add(centerPane, "Center");
mainDisplay.add(southPane, "South");

Then, in your actionPerformed, you can just do:

public void actionPerformed(ActionEvent e)
    String Label = (String) e.getActionCommand();
    if (Label.equals("Next"))
         // do the replacement
         mainDisplay.add(replacementPane, "Center");

         // repaint itself and all subcomponents  

Author Comment

ID: 1234630
Perfect! That's exactly what I needed to know.  Thanks a lot!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question