void () { // align vertically Rectangle r = getBounds(); Insets insets = getInsets(); int x = insets.left; Dimension preferredSize = scrollPane.getPreferredSize(); scrollPane.setBounds(x, (r.height - preferredSize.height) / 2, r.width - insets.left - insets.right, preferredSize.height); }