I think that's because you are specifying this
in constructor (this JPanel may not be completely initialized). Try replacing:
setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
with:
setLayout(new BorderLayout());
Note: From what we see in your code here, replacing this BoxLayout
with a BorderLayout
should not have any impact on your layout inside this panel because you don't add any component to this panel in your code. If this is not the case, please read BorderLayout
Javadoc.