Why is Swing doing this?
The preferred height of each panel added to the centre panel is 20. The BoxLayout needs to scale each of the panels to fill then entire space available. It looks like there is some kind of rounding problem when this scaling is done.
Can it be fixed?
Not sure what your exact requirement is?
If you are attempting to make each component the same height then you can use the Relative Layout. It has a property that allows you to specify what to do with remaining pixels as a result of rounding.
Edit:
Took a closer look at your code and the problem is:
//mainframe.setPreferredSize(new Dimension(800, 600));
Never set the size of the frame. That is the job of the layout manager. The size you manually set includes the titlebar and borders so all the panels are smaller than you wish and they are not divisible by 10.
// mainframe.setPreferredSize(new Dimension(800, 600));