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

I add a toolbar with some standard Delphi components to my application. Unfortunately, the
I'm working on a project with some custom Sharepoint Workflow components which I'd like
Why should companies invest in refactoring components, though it is not going to add
I have a custom editor composed of several components. Something like: class MyCellEditor extends
I would like to use factory classes and methods to generate GUI components, but
I'm in the process of porting some code from Linux to Mac OS X.
I am attempting to pull some information from my tnsnames file using regex. I
My IDE crashes any time I try add a new component to the toolbar.
So I have a module in flex in which I add a custom component.
Add service reference to Amazon service fails, saying Could not load file or assembly

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.