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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:19:21+00:00 2026-05-24T03:19:21+00:00

I want to leave the default border on my JButton s, but put empty

  • 0

I want to leave the default border on my JButtons, but put empty space around them as well. I’m using a vertical BoxLayout.

  • I originally said nothing about the borders, and got single pixel LineBorders, which I want, but the buttons all butted up against each other.

  • I then tried button[i].setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)). Rather than adding blank space around the button, it made the buttons’ areas expand. It also removed the LineBorder.

  • I then tried: button[i].setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(5, 5, 5, 5), button.getBorder()))

This gave me back the LineBorder, but rather than adding blank space outside the line, it just extended the buttons’ areas beyond the line!

I realise I can add blank boxes to space my buttons out, but I want space on the sides of them as well, which is why I want to add an EmptyBorder. I’m new to Swing, so maybe there’s an entirely better way of doing this that I don’t know about 🙂

I’m using Jython, but the API should be the same as from Java.

  • 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-24T03:19:21+00:00Added an answer on May 24, 2026 at 3:19 am

    Conceptually, the “empty borders” you want to add are not really part of the button (for example, they should not be clickable).

    This is actually a matter of layout, so you should probably check the documentation of the layout manager you are using. For example:

    • Some layout managers, such as FlowLayout, BorderLayout, or GridLayout, have hgap and vgap properties to specify the horizontal and vertical gaps between components.
    • With GridBagLayout you would set the insets of a GridBagConstraints object.
    • With BoxLayout you would add “rigid areas”, “glue”, and “fillers” (see the Box class).

    And so on.

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

Sidebar

Related Questions

i'm using a default style table ( UITableViewCellStyleSubtitle ) i want to add more
I want to make a dropdown menu using jquery, but it closes even it
What i mean is that i want to activate the mouse leave event only
want to know why String behaves like value type while using ==. String s1
Want the function to sort the table by HP but if duplicate HPs then
I want a basic: <input type=text /> And I would like the default value
how to validate joomla default text editor on blur using jQuery? This is the
I'm using the jQuery plugin that generates interactive tables called jqGrid . I want
This should be simple, but pointers to char arrays still leave me scratching my
I have a database first design. I want to have default values for my

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.