I have a JPanel with 3 buttons ( its a JPanel which is going to contain a menu with buttons and JLabels).
The buttons need to be stacked on top of each other, with a small space between them.
I have the buttons stacked with :
 BoxLayout myLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
 this.setLayout(myLayout);
 this.setPreferredSize(new Dimension(300,150));
Now the buttons are auto stacked when added, but they are all different size depending on the amount of text in it.
What I want is the buttons to be in the Center of the JPanel and have the width of the panel - 10 px on each side.
What i have:
give all the buttons:
    .setPreferredSize(new Dimension(280,20));
but it didnt make any diffrent.
To be more clear i will post the complete code so you can see what i mean:
private JButton buttonStartStop;
private JButton buttonReset;
public ViewControlsPanel()
{
    BoxLayout myLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
    this.setLayout(myLayout);
    this.setPreferredSize(new Dimension(300,150));
    buttonStartStop = new JButton("Start");
    buttonStartStop.setPreferredSize(new Dimension(280,30));
    buttonReset = new JButton("Reset");
    buttonReset.setPreferredSize(new Dimension(280,20));
    this.add(buttonStartStop);
    this.add(buttonReset);
}
I have tried to give diffrent dimension but it didnt help.
My guess is that it is possible to give the BoxLayout a propperty to give the containing components a preffered size but i cant find it.
 
     
    

