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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:46:59+00:00 2026-06-06T19:46:59+00:00

I need some advice on which Swing Components to choose in order to achieve

  • 0

I need some advice on which Swing Components to choose in order to achieve the following:

I have something like a “table” structure, that every time that I click the “Add” button, another “row” should be inserted on the “table”. Each row is composed of 2 JTextField. The problem I am having with the GridLayout (the layout used in the pictures below) is that if I add another row, then the heights of the text fields will be shortened and I don’t want that (picture on the right), I want to preserve the same height for every row.

What I would like to happen is to have the extra row appear below the last one, so that I could use the JScrollPane and scroll to see it.

enter image description here

Should I use another layout rather than the GridLayout? Maybe the AbsoluteLayout or even using the Table Component?

Thanks.

  • 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-06T19:47:02+00:00Added an answer on June 6, 2026 at 7:47 pm

    I would use a JTable and set the row height to whatever you desire. For example:

    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    
    public class TableEg {
       private static final int ROW_HEIGHT = 40;
       private static final String[] TABLE_COLUMNS = {"Foo", "Bar"};
    
       private static void createAndShowGui() {
          final DefaultTableModel tableModel = new DefaultTableModel(TABLE_COLUMNS, 2);
          JTable table = new JTable(tableModel );
          table.setRowHeight(ROW_HEIGHT);
          JScrollPane scrollpane = new JScrollPane(table);
    
          JButton addRowBtn = new JButton(new AbstractAction("Add Row") {
    
             @Override
             public void actionPerformed(ActionEvent arg0) {
                tableModel.addRow(new String[]{"", ""});
             }
          });
          JPanel btnPanel = new JPanel();
          btnPanel.add(addRowBtn);
    
          JFrame frame = new JFrame("TableEg");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(scrollpane, BorderLayout.CENTER);
          frame.getContentPane().add(btnPanel, BorderLayout.PAGE_END);
          frame.pack();
          frame.setLocationByPlatform(true);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some advice for a design which I have to implement in application.
I'm working with Symfony 2 and need some advice. I have a Controller, which
I need some advice regarding which database I should use. I want to create
I need some advice on techniques to perform page redirect in asp.net. Which one
I need some advice of how to setup my tables I currently have a
I need some advice on which library is the best choice when it comes
I need some advice on a DB I'm working in. I have the DB,
Ok, so I need some advice on which encryption method I should use for
After doing some research I need some advice. This is a small project which
Need some advice, I'm after a decent process/task manager for Ubuntu. Basically I have

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.