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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:36:15+00:00 2026-05-20T15:36:15+00:00

I have a form on my Java application which basically is to provide the

  • 0

I have a form on my Java application which basically is to provide the user with a list of data from a DB query. one idea was to use a table and populate each row with data from my resultset. However when designing the UI my team and i decided that it didnt look as smooth as we wanted. So we thought we would look into creating a custom view of the results in a panel. we wanted it to look something like:
Desired custom view

So instead of rows of a table it will look like this with one for each enquiry on the resultset.

The problem i am having is coding this. I spent a good deal of time trying to workout how to add a component to a JForm. as netbeans seem to by default set up the ui as a grouplayout? so I worked out how to add 1 panel using:

javax.swing.JLabel idLbl;
 javax.swing.JLabel jLabel1;
 javax.swing.JLabel jLabel3;
 javax.swing.JLabel jLabel5;
 javax.swing.JLabel jLabel7;
 javax.swing.JPanel jPanel1;
 javax.swing.JLabel prefContactLbl;
 javax.swing.JLabel propertyLabel;
    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    idLbl = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    propertyLabel = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    contactLabel = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    prefContactLbl = new javax.swing.JLabel();

    jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel1.setText("Enquiry Id:");
    jLabel1.setName("jLabel"+i);

    idLbl.setText("jLabel2");

    jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel3.setText("Property:");

    propertyLabel.setText("A property Address in some town with a postcode");

    jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel5.setText("Contact:");

    contactLabel.setText("A Persons Name ( 01010100011)");

    jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
    jLabel7.setText("Prefered Contact:");

    prefContactLbl.setText("Email/Phone");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(idLbl)
                    .addGap(18, 18, 18)
                    .addComponent(jLabel3)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(propertyLabel))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel7)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(prefContactLbl)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel5)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(contactLabel)))
            .addContainerGap(20, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(idLbl)
                .addComponent(jLabel3)
                .addComponent(propertyLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel7)
                .addComponent(prefContactLbl)
                .addComponent(jLabel5)
                .addComponent(contactLabel))
            .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
     getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(10 , 10, 10)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addContainerGap(100, Short.MAX_VALUE))
    );

    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(570, Short.MAX_VALUE))
    );

The main problem I am faced is adding more than 1 dynamically I am completly unsure how to go about it as all i can find is to set the layout not update it. And I cant set how many .addcomponent as its dynamic. Really confused on how to go about this.

Sorry if its hard to work out what I am trying to get across easier to think of it but putting it into words is a nightmare.

  • 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-20T15:36:16+00:00Added an answer on May 20, 2026 at 3:36 pm

    Starting off by encapsulating things a bit more will make your life much easier. Make a subclass of JPanel that represents the view for one enquiry entry: EnquiryPanel. The EnquiryPanel would have code in it that nearly matches what you pasted above, except that it will fill itself in from the constructor parameters that you pass in and it will be a JPanel itself.

    public class EnquiryPanel extends JPanel {
       public EnquiryPanel(Result dbResult) {
         // your layout code from above, but this is the content pane and
        // the fields are populated from the dbResult object
       }
    }
    

    You can then dynamically add instances of EnquiryPanel to a container panel whose layout is a vertical BoxLayout. I call this container panel ResultsPanel below.

    public class ResultsPanel extends JPanel {
      public ResultsPanel() {
        // Layout our contents vertically
        BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
        this.setLayout(layout);
      }
      // method to iterate over the results from the database
      // construct an EnquiryPanel and add that EnquiryPanel to ourselves
      public void layoutEnquiryResults(ResultCollection results) {
         for (Result result : results) {
            EnquiryPanel eqPanel = new EnquiryPanel(result);
            add(eqPanel);
         }
         revalidate();
      }
    }
    

    Finally you would add an instance of ResultsPanel to your JFrame.

    ResultsPanel resultsPanel = new ResultsPanel();
    resultsPanel.layoutEnquiryResults(myResultSet);
    getContentPane().add(resultsPanel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login.jsp page which contains a login form. Once logged in the
I have a script that appends some rows to a table. One of the
I have found this example on StackOverflow: var people = new List<Person> { new
i have a input tag which is non editable, but some times i need
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
Let say I have the following desire, to simplify the IConvertible's to allow me
This is beyond both making sense and my control. That being said here is

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.