may help you . The preferred size of a component is based on the preferred size of the components added to it. Yes, the preferred size of the JList will change as you add items to the list. However, the JList is added to a JScrollPane, so its the preferred size of the JScrollPane that is used to determine the preferred size of the JPanel.
What's the best way to keep JButtons centered in a JPanel using GroupLayout on JPanel resize
I hope this helps you . I find GroupLayout to be fine to code by hand, certainly no harder than GridBagLayout, though I can certainly see why it would be a favorite for tools to use. But it is meant for putting things into columns and rows, not for centering buttons. You have the wrong layout manager. To put a panel in the center of a screen that you want the user to be able to resize (which should be the default), you can put your panel in the BorderLayout.CENTER of a BorderLayout (which is the default layout manager on a JFrame). Now, by default, the panel will also stretch to fit the frame unless you also put some things in the NORTH, SOUTH, EAST, and/or WEST portions of the BorderLayout. Whether this works for you depends on what you're doing.