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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:13:11+00:00 2026-06-11T00:13:11+00:00

I have frame with a button and a JPanel as I named panel, I

  • 0

I have frame with a button and a JPanel as I named panel, I want after I clicked the button add an inner panel to my panel. But this but there is a problem with this! because after adding second panel it didn’t add any other panel.

Code

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import javax.swing.JTextField;


public class DrawImages extends JFrame{
    
    int i;
    public DrawImages() {
        JButton btnNewButton = new JButton("New button");
        i = 0;
        getContentPane().add(btnNewButton, BorderLayout.SOUTH);
        setMinimumSize(new Dimension(1000,150));
        final JPanel panel = new JPanel();
        panel.setSize(995, 145);
        getContentPane().add(panel, BorderLayout.CENTER);
        panel.setLayout(null);
        

        final JLabel lblNewLabel = new JLabel("New label");
        lblNewLabel.setBounds(0, 0, 46, 14);
        panel.add(lblNewLabel);
        
        btnNewButton.addActionListener(new ActionListener() 
            public void actionPerformed(ActionEvent paramActionEvent) {
                JPanel panel_1 = new JPanel();
                //getContentPane().add(panel_1, BorderLayout.NORTH);
                panel_1.setLayout(null);
                JLabel imagelable = new JLabel(new ImageIcon("c:\\good.jpg"));
                imagelable.setBounds(70, 5, 105, 65);
                panel_1.add(imagelable);
                
                JLabel lblNewLabel_4 = new JLabel("Up Label");
                lblNewLabel_4.setBounds(5, 5, 65, 35);
                panel_1.add(lblNewLabel_4);
                
                JLabel lblNewLabel_2 = new JLabel("Down Label");
                lblNewLabel_2.setBounds(5, 25, 65, 65);
                panel_1.add(lblNewLabel_2);
                lblNewLabel.setText(""+i);
                panel_1.setBounds(5+170*i, 5, 170+170*i, 70);
                panel.add(panel_1);
                i++;
            }
        });
        panel.setMinimumSize(new Dimension(995,150));
    }

    public static void main(String[]args)
    {
        DrawImages drawImages = new DrawImages();
        drawImages.setVisible(true);
    }
}
  • 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-11T00:13:13+00:00Added an answer on June 11, 2026 at 12:13 am

    Thanks for your answers but my problem is I added third arguman in every circle:

    panel_1.setBounds(5+170*i, 5, 170+170*i, 70);
    

    so my panel get bigger and bigger (event biger than my monitor) so the correct is:

    panel_1.setBounds(5+170*i, 5, 170, 70);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button that opens up a frame. Is there a way to
I want to add an image to a frame but I am not able
I realsie that similar questions have been answered here about this problem but im
I have a problem with drawing. I have a frame with one button. Using
I have a custom UITableViewCell which contains several UIButtons. Each button's frame position is
I have a button script to change the buttons in a frame based on
I have two buttons in my first android frame. ok button and cancel button.
I have a frame extends from JWindow (because I want to handle my X
I have one frame in which one TestArea is there. When I append some
I'm having small problem (I guess) of showing the JTable panel. I have class

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.