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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:10:54+00:00 2026-05-28T13:10:54+00:00

Maybe there is a similar question to this, but I couldn’t find a one.

  • 0

Maybe there is a similar question to this, but I couldn’t find a one.

Id like my program ( awt or swing ) to add controls ( like text fields ) automatically.

For example : A dialog program has 10 fields for inputting names, but I need 11 so by pressing a button a new field will appear.

Thank you in advance.

  • 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-28T13:10:54+00:00Added an answer on May 28, 2026 at 1:10 pm

    Here is an example using Box:

    enter image description here

    import java.awt.BorderLayout;
    import java.awt.event.*;
    
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    
    public class MultiJComponentsTest extends JFrame
    {
        private JButton btnAdd;
        private JPanel centerPanel;
        private Box vBox;
    
        public MultiJComponentsTest()
        {
            super("The Title");
            btnAdd = new JButton("Add new JTextField!");
            btnAdd.addActionListener(new ActionListener(){
    
                @Override
                public void actionPerformed(ActionEvent e)
                {
                    vBox.add(new JTextField(20));
                    pack();
                }
    
            });
            vBox = Box.createVerticalBox();
            centerPanel = new JPanel();
            JPanel contentPanel = (JPanel) getContentPane();
            contentPanel.setLayout(new BorderLayout());
            contentPanel.add(btnAdd, "South");
            contentPanel.add(centerPanel, "Center");
            centerPanel.add(vBox);
            pack();
        }
    
        public static void main(String args[])
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                @Override
                public void run()
                {
                    new MultiJComponentsTest().setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe there's no way to solve this the way I'd like it but I
I've looked around on SO but I couldn't find any similar question. After opening
I couldn't seem to find a similar question to this. I am currently looking
I figured this must be a common question, but I surprisingly couldn't find an
There maybe some simlar questions to this but I can't see anything that really
Maybe there is a proper term for this, but what if you want to
I call this a flash meeting, but maybe there is another more appropriate name.
I haven't exactly found the answer to this, maybe there is no best one.
Firstly, I realise that this is a very similar question to this one: Which
Maybe there's someone out in the ether that can help me with this one.

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.