0

So, I have a Calendar solution for my employers where I am using a custom look and feel (Synthetica) and each cell in the table holds a JPanel with a list of buttons and a PAGE_AXIS BoxLayout. I am trying to reduce the gaps between each button so that they abut each other, and I've tried setting the borders to null except that destroys the button appearance. I have used the following (as recommended by Oracle to view the actual size of the components) code;

setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createLineBorder(Color.red), 
    getBorder())); 

And this is what I get;

enter image description here

Setting the margin does not work with whatever border version the buttons are using. So, is there any way to find the current border that it's using? So that I can set that border's insets manually, or something like that. Basically, I need the buttons to abut each other. Any ideas?

Clarification: I want the button's themselves to stay the same size, but I want the white space around them (highlighted inside of the red borders) to be gone,

Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
  • I think that's not a problem with the button, but with the Box Layout itself. Have you tried another LayoutManager? – Gabriel Câmara Nov 11 '13 at 17:43
  • @GabrielCâmara - The red lines around the buttons mark the furthest point out of the JButton components, so the components are actually right next to each other but have extra space around the outside within the component. So it's not the layout that is the issue. At least I presume not anyway. – Rudi Kershaw Nov 12 '13 at 09:32

2 Answers2

3

Several possibilities should be considered:

  • Manipulate the button's bound properties: setBorderPainted(false), et al., as suggested here.

  • See if a suitable sizeVariant is available, as shown here.

  • Use a custom UI delegate based on BasicButtonUI, as shown here and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Hey, thanks for your answer. I tried the top two suggestions and got nothing (the space between them still isn't reduced). Looking into the last point now, but I'm having a little trouble understanding. – Rudi Kershaw Nov 12 '13 at 09:34
  • In any approach, you can override [`getPreferredSize()`](http://stackoverflow.com/q/7229226/230513), but beware of [this](http://stackoverflow.com/a/12532237/230513). – trashgod Nov 12 '13 at 18:18
  • 1
    Sorry for the delay. Realized I never accepted an answer on this one. I used a custom UI as in your last suggestion. – Rudi Kershaw Feb 04 '14 at 10:44
1

I tried to get the Synthetica L&F to have a look but seems as though you have to create an account which I did not want to do. Anyways, a quick look around the website and I found a page which indicates how you can see and configure some of the values set in the L&F. Might be worth having a look there.

http://www.jyloo.com/synthetica/customize/

patois50
  • 44
  • 1