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

  • Home
  • SEARCH
  • 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 4010476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:00:18+00:00 2026-05-20T09:00:18+00:00

I am working on a simple desktop application with java. There is a menu

  • 0

I am working on a simple desktop application with java. There is a menu bar, when the user clicks on menu item 1 then the content will change to form A. When a user clicks on menu item 2 then the content will display form B.

How could i achieve this?

using the same window and just the content change.

  • 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-20T09:00:18+00:00Added an answer on May 20, 2026 at 9:00 am

    A sample for you, I just did to refresh my swing knowledge..

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    
    public class FrmChange extends JFrame{
    
    private JPanel panel1 = new JPanel();
    private JPanel panel2 = new JPanel();
    
    public FrmChange(){
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        initMenu();
        panel1.setBackground(Color.BLUE);
        panel2.setBackground(Color.RED);
        setLayout(new BorderLayout());
    }
    
    private class MenuAction implements ActionListener {
    
        private JPanel panel;
        private MenuAction(JPanel pnl) {
            this.panel = pnl;
        }
        @Override
        public void actionPerformed(ActionEvent e) {
            changePanel(panel);
    
        }
    
    }
    
    private void initMenu() {
        JMenuBar menubar = new JMenuBar();
        JMenu menu = new JMenu("Menu");
        JMenuItem menuItem1 = new JMenuItem("Panel1");
        JMenuItem menuItem2 = new JMenuItem("Panel2");
        menubar.add(menu);
        menu.add(menuItem1);
        menu.add(menuItem2);
        setJMenuBar(menubar);
        menuItem1.addActionListener(new MenuAction(panel1));
        menuItem2.addActionListener(new MenuAction(panel2));
    
    }
    
    private void changePanel(JPanel panel) {
        getContentPane().removeAll();
        getContentPane().add(panel, BorderLayout.CENTER);
        getContentPane().doLayout();
        update(getGraphics());
    }
    
    public static void main(String[] args) {
        FrmChange frame = new FrmChange();
        frame.setBounds(200, 200, 300, 200);
        frame.setVisible(true);
    
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on converting a very simple java desktop application to run in java
Hi I am working on a simple desktop application, it needs to handle some
I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display
i am working on a simple web app which has a user model and
I'm working on a simple 2D game engine in Java, and having no trouble
I am working on a simple notification service that will be used to deliver
I'm working on a simple application to start learning my way around WPF. I
I'm working on an application that needs to quickly render simple 3D scenes on
I have a desktop application that will 'sync' with an iPhone application. The sync
I am trying to get a simple (all front-end) application working offline on ipad,

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.