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 7594539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:26:31+00:00 2026-05-30T21:26:31+00:00

I am really new to GUI programming in Java, I did a lot of

  • 0

I am really new to GUI programming in Java, I did a lot of research and I couldn’t find an answer to this problem.

I have a simple JFrame with a menu, and inside this JFrame I have a JPanel with a log in form (were users input their username and password), and then I want to change that JPanel to another JPanel depending on what users want to do.

What would be the best way of doing this? I think that stacking JPanels is OK. But after I add new JLayeredPanels in Netbeans they don’t stack. I read somewhere that I should use Z ordering or something like that, but I can’t find it on the designer view.

Well, thank you very much for your patience!

  • 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-05-30T21:26:33+00:00Added an answer on May 30, 2026 at 9:26 pm

    CardLayout class has a useful API that can serve your requirements. Using methods like next(), first(), last() can be helpful.
    I’ve prepared a simple demonstration of changing panels within a parent panel and/or frame.
    Take a look at it:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class PanelChanger implements ActionListener
    {
        JPanel panels;
    
        public void init(Container pane)
        {
            JButton switcher = new JButton("Switch Active Panel!");
            switcher.addActionListener(this);
    
            JPanel login = new JPanel();
            login.setBackground(Color.CYAN);
            login.add(new JLabel("Welcome to login panel."));
    
            JPanel another = new JPanel();
            another.setBackground(Color.GREEN);
            another.add(new JLabel("Yeah, this is another panel."));
    
            panels = new JPanel(new CardLayout());
            panels.add(login);
            panels.add(another);
    
            pane.add(switcher, BorderLayout.PAGE_START);
            pane.add(panels, BorderLayout.CENTER);
        }
    
        public void actionPerformed(ActionEvent evt)
        {
            CardLayout layout = (CardLayout)(panels.getLayout());
            layout.next(panels);
        }
    
        public static void main(String[] args)
        {
             JFrame frame = new JFrame("CardLayoutDemo");
             PanelChanger changer = new PanelChanger();
             changer.init(frame.getContentPane());
             frame.pack();
             frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a relatively new programmer so this may be a really simple question
I've been programming in Java for a little while now but have never really
I'm new GUI and programming as whole and so far I have a general
Hey everyone! I am new to blackberry programming although I do have some java
I`m really new in Objective-C and Mac OSX programming. Can someone give me simple
I'm really new to Java, especially working with GUI in Java. I want to
im really new to linq-to-SQL so this may sound like a really dumb question,
I am really new to Python and I have been looking for an example
I'm really new to HTML, but I can't find anywhere how to return the
I'm really new to VSTO so sorry if this is a newbie question. I'm

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.