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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:38:40+00:00 2026-06-03T07:38:40+00:00

I have a following JFrame. public class AddActivityWindow extends JFrame { //declaration of components

  • 0

I have a following JFrame.

public class AddActivityWindow extends JFrame {

    //declaration of components go here
     ...
    public AddActivityWindow(ActivityStore store) {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel pnl_date = new JPanel();
        JLabel lbl_date = new JLabel("X");
        pnl_date.add(lbl_date);
        add(pnl_date);


        pnl_activities = new JPanel();
        JLabel lbl_act = new JLabel("Y");
        pnl_activities.add(lbl_act);
        add(pnl_activities);

        setLocationRelativeTo(null);
        setVisible(true);

    }
}

When I create this Frame I was expecting that it would create a frame with two panels. But, I only see the second panel (i.e.) I only see Y on the screen and not X. However, if I remove the code for the second panel, then I can see X.

What happens when I add the second panel. Why does the first panel not show up in the frame?

  • 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-03T07:38:42+00:00Added an answer on June 3, 2026 at 7:38 am

    You should be using a different Layout Manager, Have a look at : A Visual Guide to Layout Managers to select one for you.

    This works fine for me ,

    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class FrameTest extends JFrame {
    
        public FrameTest() {
            setLayout(new FlowLayout());
            setSize(150, 150);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            JPanel pnl_date = new JPanel();
            JLabel lbl_date = new JLabel("X");
            pnl_date.add(lbl_date);
            add(pnl_date);
    
    
            JPanel pnl_activities = new JPanel();
            JLabel lbl_act = new JLabel("Y");
            pnl_activities.add(lbl_act);
            add(pnl_activities);
    
            setLocationRelativeTo(null);
            setVisible(true);
    
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new FrameTest().setVisible(true);
    
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class Test extends JFrame implements ActionListener{ private static
Hello, I have the following problem: public class TestCombo extends JFrame{ public TestCombo() {
Ok, I have the following code. public class MyProgressBar extends JPanel implements MyData, Serializable
I have the following: import javax.swing.JFrame; public class Directions { public Directions(){ JFrame frame
I have code similar to the following: public class myButton extends JButton() { public
I have the following code: import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; public
I have following class. In this, Iris is another class with some attributes. public
I have following class public abstract class Rule { protected Rule() { Nodes =
I have the following: import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JLayeredPane; import javax.swing.JFrame; import javax.swing.BorderFactory;
I have a JFrame and following components. JButton = jButton1 Progress Bar = progressBar

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.