Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8035973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:28:09+00:00 2026-06-05T02:28:09+00:00

Can anyone tell me how to go about coding for navigation between multiple JPanel

  • 0

Can anyone tell me how to go about coding for navigation between multiple JPanel classes taking the event trigger from JButton from the objects (panels) themselves? I have read about CardLayout. The panel can be swapped from the events happening in the parent panel. What I want to achieve is on click of a button embedded in the panel, it should should disappear or a desired panel should be displayed. Can’t seem to find a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:28:10+00:00Added an answer on June 5, 2026 at 2:28 am

    There is nothing about CardLayout that prevents switching cards from actions of children within the cards.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Testing extends JFrame {
    
        private JPanel cardHolder;
        private CardLayout cards;
        private static final String cardA = "A";
        private static final String cardB = "B";
    
        private class Switcher implements ActionListener{
            String card;        
            Switcher(String card) { this.card = card; }
            @Override
            public void actionPerformed(ActionEvent e) {
                cards.show(cardHolder, card);
            }
        }
    
        private void run() {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
    
            JPanel pa = new JPanel();
            JButton ba = new JButton("Switch to B");
            ba.addActionListener(new Switcher(cardB));
            pa.add(ba);
            pa.setBackground(Color.CYAN);
    
            JPanel pb = new JPanel();
            JButton bb = new JButton("Switch to A");
            bb.addActionListener(new Switcher(cardA));
            pb.add(bb);
            pb.setBackground(Color.MAGENTA);
    
            cardHolder = new JPanel();
            cards = new CardLayout();
            cardHolder.setLayout(cards);
            cardHolder.add(pa, cardA);
            cardHolder.add(pb, cardB);
            add(cardHolder);
            pack();
            setVisible(true);
        }
    
        public static void main(String[] args) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        new testing().run();
                    }
                });
            } catch (Exception ex) { }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate graph from my database data can anyone tell me about
Can anyone tell me about the difference between class variables and class instance variables?
can anyone please tell about showing message box from MVC controller? The scenario is
Can anyone tell me about the below warning refers to in android eclipse. Keybinding
can anyone tell me how to extract images from a video? what i ve
Can anyone tell me about using (Steel Bank) Common Lisp for writing GUIs via
Can anyone tell me about SSL and how it can be used to secure
Can anyone tell me what the difference is between NSLog and DLog ? I
Can anyone tell me about the way to resize my image view to show
Can anyone tell me about the architectural considerations for high traffic web applications? Links

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.