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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:26:23+00:00 2026-06-10T16:26:23+00:00

I am coding a contact list application in eclipse using Java Swing. How can

  • 0

I am coding a contact list application in eclipse using Java Swing.
How can I get a simple table layout that contains just columns and rows?
I don’t want row or column labels.

Something like this:

first name: john
middle name: franklin
last name: doe

Where the names would be editable text boxes etc.

What’s the best component to use?

I will also have buttons below the text fields.
Currently I have a JFrame which is running correctly. It pulls up a window that has my menu options correct. But when I try to do this:

myFrame.setLayout(new GridLayout(6, 2)); 

I get an error. I would like to have a grid layout of two columns and 5 rows (maybe 6).
I want to have a label on the left column, and a text box on the right column.
then two buttons at the bottom, centered.

  • 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-10T16:26:24+00:00Added an answer on June 10, 2026 at 4:26 pm

    You’d better of breaking your fields and controls (buttons) into separate panels, this allows you to supply different layout managers for each.

    I’d start with a base JPanel using a BorderLayout.

    Onto this, I’d add the “fields” panel at the CENTER position and the controls (buttons) at the SOUTH position.

    For the fields, I’d use a GridBagLayout, but I’m picky like that, and for the controls panel I’d probably use a FlowLayout (unless you have access to a nice ButtonLayout manager ;))

    This means you could end up with something like

    enter image description here

    UPDATED with code sample

    public class FormPanel extends JPanel {
    
        private JTextField fldFirstName;
        private JTextField fldMiddleName;
        private JTextField fldLastName;
        private JTextField fldDateOfBirth;
        private JTextField fldEMail;
        private JButton okButton;
        private JButton cancelButton;
    
        public FormPanel() {
    
            setLayout(new BorderLayout());
            add(createFieldsPane());
            add(createButtonsPane(), BorderLayout.SOUTH);
    
        }
    
        public JPanel createButtonsPane() {
    
            JPanel panel = new JPanel(new FlowLayout());
            panel.add((okButton = createButton("Ok")));
            panel.add((cancelButton = createButton("Cancel")));
    
            return panel;
    
        }
    
        protected JButton createButton(String text) {
    
            return new JButton(text);
    
        }
    
        public JPanel createFieldsPane() {
    
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2, 2, 2, 2);
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.anchor = GridBagConstraints.WEST;
    
            panel.add(createLabel("First Name:"), gbc);
            gbc.gridy++;
            panel.add(createLabel("Middle Name:"), gbc);
            gbc.gridy++;
            panel.add(createLabel("Last Name:"), gbc);
            gbc.gridy++;
            panel.add(createLabel("Date of Birth:"), gbc);
            gbc.gridy++;
            panel.add(createLabel("EMail:"), gbc);
    
            gbc.gridy = 0;
            gbc.gridx++;
            gbc.weightx = 1;
            panel.add((fldFirstName = createField()), gbc);
            gbc.gridy++;
            panel.add((fldLastName = createField()), gbc);
            gbc.gridy++;
            panel.add((fldMiddleName = createField()), gbc);
            gbc.gridy++;
            panel.add((fldDateOfBirth = createField()), gbc);
            gbc.gridy++;
            panel.add((fldEMail = createField()), gbc);
    
            JPanel filler = new JPanel();
            filler.setOpaque(false);
    
            gbc.gridy++;
            gbc.weightx = 1;
            gbc.weighty = 1;
            panel.add(filler, gbc);
    
            return panel;
    
        }
    
        protected JLabel createLabel(String text) {
    
            return new JLabel(text);
    
        }
    
        protected JTextField createField() {
    
            JTextField field = new JTextField(12);
            return field;
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After coding and testing a Java application (lets say with Eclipse, but not necessarily)
I am using Simple Listview to display Email addresses from Contact List. Its working
Right now I have one web service which is created in java using eclipse
Coding i came around to check for the vararg performance of Java. I write
While coding python I'm using only 2 spaces to indent, sure PEP-8 really recommend
I'm trying to set up a simple PHP contact form for a website and
I am coding a site in php and I am currently on the contact
I'm trying to make a simple contact form for my website, so I bought
I've been designing and coding up my website and the simple drop down menu
I am coding a site in PHP that will allow a user to view

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.