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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:30:03+00:00 2026-06-05T12:30:03+00:00

I am very new to Swing, and I’m trying to make a GUI. Using

  • 0

I am very new to Swing, and I’m trying to make a GUI.
Using Netbeans’ GUI creator thing, I managed to make something I liked. But it makes me feel bad that I used the editor for this, so now I am trying to make the same design using code.
Here is a picture of what I am trying to make:
what I want to make
Right now I am just focusing on creating the “Criteria” section (yes I know I spelled it wrong in the picture)
Here is what I currently have so far:
what I currently have
I’ve highlighted in red where I want to increase the margin:

  • Between the right of the text boxes and left of the labels
  • Between the top of the Criteria panel and the JFrame
  • Between the left and right sides of the panel and the JFrame

I come from web development where increasing the margins is what I want to do. If this is incorrect terminology, please inform me.
Here is the code I am currently using:

public class Criteria extends JPanel {
    JLabel JobLabel = new JLabel();
    JLabel BoxLabel = new JLabel();
    JLabel PartLabel = new JLabel();
    JTextField JobInput = new JTextField();
    JTextField BoxInput = new JTextField();
    JTextField PartInput = new JTextField();

    public Criteria() {
        setLayout(new FlowLayout(FlowLayout.LEADING));
        setBorder(BorderFactory.createTitledBorder("Criteria"));
        JobLabel.setText("Job");
        JobLabel.setLabelFor(JobInput);
        BoxLabel.setText("Box");
        BoxLabel.setLabelFor(BoxInput);
        PartLabel.setText("Part");
        PartLabel.setLabelFor(PartInput);
        JobInput.setColumns(8);
        BoxInput.setColumns(8);
        PartInput.setColumns(8);
        add(JobLabel);
        add(JobInput);
        add(BoxLabel);
        add(BoxInput);
        add(PartLabel);
        add(PartInput);
    }
}

I don’t know how I would add margin to these components, so help would be very much appreciated. If I cannot achieve this effect with FlowLayout, then please tell me what I should use instead.

  • 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-05T12:30:04+00:00Added an answer on June 5, 2026 at 12:30 pm

    Swing tends to call margins or borders ‘gaps’. The FlowLayout class (along with a few other layout classes) allows you to set the horizontal and vertical gaps in its constructor, like so:

    private static final int PADDING = 3;   // for example
    ...
        setLayout(new FlowLayout(FlowLayout.LEADING, PADDING, PADDING));
    

    This would add padding between the labels and their text boxes, however, but you could wrap each pair in a JPanel (probably with a FlowLayout). I would make a custom component class for this.

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

Sidebar

Related Questions

I created a program with a Swing GUI in NetBeans a while back using
I'm trying to use scala.swing package for my gui's. Before that, I was using
Very new to FluentNHibernate, but I'm also excited about the area. I've recently started
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Very new to XSL (and XML for that matter), but I need to step
Very new to using Raphael.js I'm looking at the tutorials and I am able
Very new mobile developer here... I am trying to retrieve a list of tweets
I'm very new to C#. My boss asked me to wrote some code using
I'm using Netbean's form creator and I'm trying out some things. I'm not sure
I'm creating an application in Swing using NetBeans. I would like to be able

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.