Try using Window#pack
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. The resulting width and height of the window are automatically enlarged if either of dimensions is less than the minimum size as specified by the previous call to the setMinimumSize method.
If the window and/or its owner are not displayable yet, both of them are made displayable before calculating the preferred size. The Window is validated after its size is being calculated.
Updated with example
Without a SSCCE (working example), it's impossible to fully diagnose your problem. Let me demonstrate...
So, based on your description, I can create this without any issues...
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
public class TestPack {
public static void main(String[] args) {
new TestPack();
}
public TestPack() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TopPanel(), BorderLayout.NORTH);
frame.add(new MiddlePanel(), BorderLayout.CENTER);
frame.add(new UpdatePanel(), BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TopPanel extends JPanel {
public TopPanel() {
setBackground(Color.red);
add(new JLabel("I'm on top"));
}
}
public class MiddlePanel extends JPanel {
public MiddlePanel() {
setLayout(new BorderLayout());
add(new JScrollPane(new JTable(new DefaultTableModel(new Object[]{"A", "B", "C"}, 5))));
}
}
public class UpdatePanel extends JPanel {
public UpdatePanel() {
for (int index = 0; index < 5; index++) {
add(new JLabel(Integer.toString(index)));
add(new JTextField(5));
}
add(new JButton("Button"));
}
}
}
But obviously, you're doing something different. Take the time to update your question with a working example, otherwise there's nothing more we can possible do