3

I am currently building a project which include a couple of buttons, and I am trying to vertically align these buttons in the center of the panel. I am also trying to make them the exact same size (like new Dimension(15, 100)).

For the part where I am trying to center the buttons I have tried to use BoxLayout, which works fine until I try to make the buttons the same size.. I have tried to use

myButton.setSize(new Dimension(15, 100))
myButton.setPreferredSize(new Dimension(15, 100));
myButton.setMinimumSize(new Dimension(15, 100));

and for the BoxLayout part, I am using this code piece

buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));

which works quite well, but it is the centering/size-specification that wont work for me..

Krease
  • 15,805
  • 8
  • 54
  • 86
Burro
  • 33
  • 8
  • 5
    Why not simply put the JButtons into a JPanel that uses a `GridLayout(0, 1, 0, ??)` where ?? is a number that represents the desired space between buttons? The first 0, and 1 parameters means one column with a variable number of rows. – Hovercraft Full Of Eels Jan 10 '13 at 22:16
  • 2
    You probably don't really want them a fixed size in pixels once someone runs your application on a computer with a different screen resolution. @HovercraftFullOfEels suggestion can help with that. – Lee Meador Jan 10 '13 at 22:23

0 Answers0