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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:53:17+00:00 2026-05-13T15:53:17+00:00

If I add components like JButton s on the East or West side, how

  • 0

If I add components like JButtons on the East or West side, how do I prevent it from hugging the side of the screen? I want some space between the JButtons and the edge of the screen.

  • 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-13T15:53:17+00:00Added an answer on May 13, 2026 at 3:53 pm

    call setBorder on your JButton like this:

    setBorder( new EmptyBorder( 3, 3, 3, 3 ) )
    

    From the JavaDoc, an EmptyBorder is a “transparent border which takes up space but does no drawing”. In my example it shall take 3 pixels respectively top, left, bottom and right.

    Complete code whose purpose is only to show how to use EmptyBorder:

    import java.awt.BorderLayout;
    import java.awt.Container;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.border.EmptyBorder;
    
    public class ALineBorder {
    
        public static void main(String args[]) {
            JFrame frame = new JFrame("Line Borders");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JButton button1 = new JButton("Button1");
            button1.setBorder( new EmptyBorder( 8, 8, 8, 8 ) );
            JButton button2 = new JButton("Button2");
            JButton button3 = new JButton("Button3");
            button3.setBorder( new EmptyBorder( 16, 16, 16, 16 ) );
            Container contentPane = frame.getContentPane();
            contentPane.add(button1, BorderLayout.WEST);
            contentPane.add(button2, BorderLayout.CENTER);
            contentPane.add(button3, BorderLayout.EAST);
            frame.pack();
            frame.setSize(300, frame.getHeight());
            frame.setVisible(true);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is some desire to add widget-like components to the Default page of our
I want to make JButton from image. But when i do it like this:
d1=new JDialog(); d1.setSize(200, 100); t1=new JTextField(); t1.setBounds(10,10,40,20); d1.add(t1); I want to add components in
I'm using .NET 2.0 Windows Forms and want to add drawing components such as
In my app I see terrible performance when I add some custom components to
I want to add a vertical JSeparator between two components using a GridBagLayout. The
I have a MigLayout that I'd like to add components to dynamically, while keeping
How to add any Component like a JButton on the JFrame TitleBar in java
The .add method appends components to the end of another component. I'm trying to
I am creating a page through the core service. I want to add component

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.