Just think about it a bit - I hope you have.
Your original version creates the panel in the TestClass() constructor by calling the CustomPanel() constructor. The CustomPanel() constructor adds all of the components to the panel while it has the default FlowLayout. After the CustomPanel() constructor is done, control returns to the TestClass() constructor which then sets the panel's layout to BorderLayout, but at that point it's too late. The components have already been added to the panel, and changing the layout has no effect - at least not until more components are added to the panel, and then I'm not sure what will happen. I think it won't be pleasant. In fact, that might be why you sometimes saw a blank. Perhaps the pack() statement did something to the panel using the new layout, but I'm not sure.