Incorrect JPanel position in GridBagLayout
问题 im using GridBag to display some JPanels with images inside a JScrollPane. When there are 3 or more images the GridBagConstraints work ok but when i have 1 or 2, they get aligned to the center of the JScrollPane instead of being in their position in the top (like in a gallery) Here is my code: JPanel jPanel1 = new JPanel(); GridBagLayout layout = new GridBagLayout(); jPanel1.setLayout(layout); GridBagConstraints gbc = new GridBagConstraints(); JPanel photo = new JPanel(); Dimension d = new