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

The Archive Base Latest Questions

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

Hi i am new to java swing. i have to add buttons dynamically ,

  • 0

Hi i am new to java swing.
i have to add buttons dynamically , when i try to add those buttons dynamically it does not add to panel when it is in free layout. it accepts any one layout like null layout or gridbaglayout.

Is there any other way to add components dynamically with free layout?

  • 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:09:46+00:00Added an answer on June 3, 2026 at 7:09 am

    I assume that with “free layout”, you are referring to the Free Design Layout, also called GroupLayout developed by Netbeans. The basic idea behind this layout is the convenience it offers when designing interactively and adding components with simple visual support using GUI builders.

    The GUI builder generates the necessary code that supports the correct placement of the components. Here is the automatically generated code for placing two JButtons on a JPanel with Free Design Layout:

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jButton1)
                    .addContainerGap())
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(0, 217, Short.MAX_VALUE)
                    .addComponent(jButton2)
                    .addGap(96, 96, 96))))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jButton1)
            .addGap(100, 100, 100)
            .addComponent(jButton2)
            .addContainerGap(140, Short.MAX_VALUE))
    );
    

    As you can see the cost of easy interactive placement is passed on to the resulting code. This makes this layout not really suitable for dynamic component handling.

    On the other hand FlowLayout or GridLayout allow you to deal with dynamic components programmatically better.
    You can also always add a FlowLayout JPanel to a GroupLayout JPanel, in order to get the best of both layouts.

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

Sidebar

Related Questions

I am new to java swing. I have pasted my code below for your
I am new to java Swing and I need a tool to develop attractive
I'm new to Java Swing applications and I'd like to port an old WindowsForm
I'm new in netbeans and java swing, but also confused. I put some JLabel's
I'm new to java.I'm creating a swing based UI. I've created 2 frames, each
I have developed a Java Swing application, which uses the SwingWorker class to perform
I have the following code: package example; import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.JFrame; import
I am trying to build an MVC application in Java Swing. I have a
Hi I am new to java and I thought I'd try produce a game
I've been tasked with doing refactoring to a Java Swing application we have here

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.