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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:41:30+00:00 2026-05-23T00:41:30+00:00

How can I make a gui layout in java which is column based? by

  • 0

How can I make a gui layout in java which is column based? by that i mean:

JLabel
JTextField
JLabel
JTextField
JLabel
JTextField

I want them all stacked on to of each other, rather than side by side. In the past I’ve used FlowLayout which isn’t suitable, and gridLayout which makes each component much larger than I require. Any ideas?

  • 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-23T00:41:30+00:00Added an answer on May 23, 2026 at 12:41 am

    Look at BoxLayout, but more important, go through the layout manager tutorial to get an overview of all the user-friendly layout managers.

    Edit 1:
    Also, GridLayout sometimes works well in this situation, but you may want to place your JTextFields inside of JPanels and add the JPanels to the grid, so that the JTextFields aren’t huge looking.

    Edit 2:
    If you have a bunch of JTextFields with associated JLabels, I’ve had success and fun working from an array of String that represents the JLabel texts, and then placing the JTextFields into a Map<String, JTextField> so that I can easily get a reference to the JTextField based on it’s related String. Example to follow…

    Edit 3
    as promised, the example:

    import java.awt.*;
    import java.awt.event.*;
    import java.util.HashMap;
    import java.util.Map;
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class LabelsAndFields {
       public static final String[] LABEL_TEXTS = {
          "Sunday", "Monday", "Tuesday",
          "Wednesday", "Thursday", "Friday", "Saturday"};
    
       private JPanel mainPanel = new JPanel();
       private static final int FIELD_COLS = 10;
       private Map<String, JTextField> textFieldMap = new HashMap<String, JTextField>();
    
       public LabelsAndFields() {
          mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
          for (String labelText : LABEL_TEXTS) {
             JTextField textField = new JTextField(FIELD_COLS);
             textFieldMap.put(labelText, textField);
             JPanel panel = new JPanel(new BorderLayout());
             panel.add(new JLabel(labelText), BorderLayout.NORTH);
             panel.add(textField);
             int gap = 8;
             panel.setBorder(BorderFactory.createEmptyBorder(gap, gap, gap, gap));
             mainPanel.add(panel);
          }
       }
    
       public String getText(String labelTextKey) {
          JTextField field = textFieldMap.get(labelTextKey);
          if (field == null) {
             throw new IllegalArgumentException(labelTextKey + "is not a valid textFieldMap Key");
          }
    
          return field.getText();
       }
    
       public void setText(String labelTextKey, String text) {
          JTextField field = textFieldMap.get(labelTextKey);
          if (field == null) {
             throw new IllegalArgumentException(labelTextKey + "is not a valid textFieldMap Key");
          }
    
          field.setText(text);
       }
    
       public JPanel getMainPanel() {
          return mainPanel;
       }
    
       private static void createAndShowUI() {
          final LabelsAndFields labelsAndFields = new LabelsAndFields();
    
          JButton showAllTextBtn = new JButton(new AbstractAction("Show All Text") {
             @Override
             public void actionPerformed(ActionEvent arg0) {
                for (String labelText : LabelsAndFields.LABEL_TEXTS) {
                   System.out.printf("%10s: %s%n", labelText, labelsAndFields.getText(labelText));
                }
             }
          });
    
          JFrame frame = new JFrame("LabelsAndFields");
          frame.getContentPane().add(labelsAndFields.getMainPanel(), BorderLayout.CENTER);
          frame.getContentPane().add(showAllTextBtn, BorderLayout.SOUTH);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i make my Java Swing GUI Components [Right To Left] for Arabic
I was wondering how I can make a GUI that looks like Media Center,
I'm dying to know how I can make a GUI for ffmpeg and jhead
SUMMARY How can I make my GUI application run on windows startup on a
How can make a link within a facebox window that redirects it to another
In C# you can make a block inside of a method that is not
I need to make a GUI Application for my class , so I want
I would like to build a GUI shell for DOS so I can make
I want to make a GUI and do it through code rather than dragging
I am searching any java library or 3rd party library using which I can

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.