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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:03:18+00:00 2026-06-17T06:03:18+00:00

I have three Java classes: a JFrame: HomeView, a JPanel: TopicListView, another JPanel: ReplyListView.

  • 0

I have three Java classes:

a JFrame: HomeView,
a JPanel: TopicListView,
another JPanel: ReplyListView.

In HomeView, I have a menu item that I can click to display TopicListView. In TopicListView, I want to have a button that I can click to display ReplyListView. When the button is clicked, it will invoke the openReplyListView() method. The method will create a new JPanel and replace the current JPanel with it. However, the code in openReplyListView() do not work.

Note: I am not using CardLayout.

Any help would be appreciated on how to get this working.

Thanks in advance.

HomeView class:

public class HomeView extends JFrame {

private JPanel contentPane;
private JMenuBar menuBar;
private JMenu mnForum;
private JMenuItem mntmReply;
private JMenuItem mntmTopic;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                HomeView frame = new HomeView();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public HomeView() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 1280, 720);
    setJMenuBar(getMenuBar_1());
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
}

private JMenuBar getMenuBar_1() {
    if (menuBar == null) {
        menuBar = new JMenuBar();
        menuBar.add(getMnForum());
    }
    return menuBar;
}
private JMenu getMnForum() {
    if (mnForum == null) {
        mnForum = new JMenu("Forum");
        mnForum.add(getMntmTopic());
        mnForum.add(getMntmReply());
    }
    return mnForum;
}
private JMenuItem getMntmReply() {
    if (mntmReply == null) {
        mntmReply = new JMenuItem("Reply");
        mntmReply.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                JPanel panel = new ReplyView();
                getContentPane().removeAll();
                getContentPane().add(panel);
                getContentPane().validate();
                getContentPane().repaint();
            }
        });
    }
    return mntmReply;
}


private JMenuItem getMntmTopic() {
    if (mntmTopic == null) {
        mntmTopic = new JMenuItem("Topic");
        mntmTopic.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                JPanel panel = new TopicListView();
                getContentPane().removeAll();
                getContentPane().add(panel);
                getContentPane().validate();
                getContentPane().repaint();
            }
        });
    }
    return mntmTopic;
}
}

TopicListView class:

public class TopicListView extends JPanel {
private JTable table;
private JScrollPane scrollPane;
private JLabel lblTopics;


/**
 * Create the panel.
 */
public TopicListView() {
    setLayout(null);
    add(getTable());
    add(getScrollPane());
    add(getLblTopics());
}

**Code snippet for the table and the scrollpane:**


private void openReplyListView(){
    JPanel panel = new ReplyListView();
    getContentPane().removeAll();
    getContentPane().add(panel);
    getContentPane().validate();
    getContentPane().repaint();

}

ReplyListView class (In general it’s the same as TopicListView)

public class ReplyListView extends JPanel {
private JTable table;
private JScrollPane scrollPane;
private JLabel lblTest;

/**
 * Create the panel.
 */
public ReplyListView() {
    setLayout(null);
    add(getTable());
    add(getScrollPane());
    add(getLblTest());

}
private JTable getTable() {
    if (table == null) {
        table = new JTable();
        table.setBounds(414, 114, 464, 354);
    }
    return table;
}
private JScrollPane getScrollPane() {
    if (scrollPane == null) {
        scrollPane = new JScrollPane(getTable());
        scrollPane.setBounds(414, 114, 464, 349);
    }
    return scrollPane;
}
private JLabel getLblTest() {
    if (lblTest == null) {
        lblTest = new JLabel("TEST");
        lblTest.setFont(new Font("Tahoma", Font.PLAIN, 30));
        lblTest.setBounds(593, 35, 81, 68);
    }
    return lblTest;
}
}
  • 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-17T06:03:20+00:00Added an answer on June 17, 2026 at 6:03 am

    Your TopicListView have no LayoutManger (i.e. setLayout(null) in constructor).

    It’s usually a bad idea. (I’m pretty sure that’s the cause of your problem)

    Try something like this

    private void openReplyListView(){
        JPanel panel = new ReplyListView();
        removeAll();
        setLayout(new BorderLayout());
        add(panel, BorderLayout.CENTER);
        validate();
        repaint();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application written in pure/basic Java without GUI. I have three classes
I have these three classes: Command: package pack; public abstract class Command impements java.io.Serializable
I have multiple classes and threads that need to write to a Java Swing
In our application we have two or three classes which contains the entire Java
I have three classes. Input.java (This is the gui class) This class takes in
I have three java projects that are being included in the main project. 2
i have three classes : CustomerData.java import java.util.Date; public class CustomerData { private String
I have three classes: xyz/url/core/datastore/ObjectBase.java xyz/url/core/test/hibernate/BaseClass.java xyz/url/core/test/hibernate/ChildClass.java Their code: ObjectBase package xyz.url.core.datastore; import java.util.Date;
Is there a way to force classes in Java to have public static final
I have one java project in netBeans. There are some packages, and classes in

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.