You have several options:
Customize the component in the internal panel using the LayoutManager , which does not resize your component.
Use a more sophisticated LayoutManager than BorderLayout . It seems to me that GridBagLayout better suited to your needs.
An example of the first solution:
import java.awt.*; import javax.swing.*; public class FrameTestBase extends JFrame { public static void main(String args[]) { FrameTestBase t = new FrameTestBase(); JPanel mainPanel = new JPanel(new BorderLayout());
Result:

The green component is placed in BorderLayout.CENTER , the red component supports the preferred size.
source share