I got components in layout as I wish to have them. Unfortunately 2nd row doesn't start as expected bellow first one, but directly under it (you can see portion of text draw on panel, should be visible whole).

I know thattoolbar should have height of 60
sidebar where thumbnails goes will be wide 185
rest of the parameters are relative
I tried to move two panels from second row to completely separate panel, but it sort of back-fired as they then did not show at all.

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import pdfrotator.tools.Dimensions;

public class RottrMainPanel extends JPanel{

    public RottrMainPanel(){
        super();
        setPanel();
    }

    private void setPanel(){
        Dimension dim = new Dimensions().getMaxDimension();
        setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();

        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.NORTHWEST;
        //gbc.weighty = 0.0;
        gbc.gridheight = 60;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridx = 0;
        gbc.gridy = 0;
        RottrToolBar rottrToolBar = new RottrToolBar();
        add(rottrToolBar, gbc);

        gbc.insets = new Insets(10, 10, 10, 10);
        gbc.fill = GridBagConstraints.VERTICAL;
        gbc.ipadx = 185;
        //gbc.gridheight = GridBagConstraints.RELATIVE;
        gbc.gridx = 0;
        gbc.gridy = 1;
        RottrThumbnailsPanel rottrThumbnailsPanel = new RottrThumbnailsPanel();
        JScrollPane jspThumbnails = new JScrollPane(rottrThumbnailsPanel,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(jspThumbnails, gbc);

        gbc.fill = GridBagConstraints.BOTH;
        /*gbc.gridwidth = GridBagConstraints.RELATIVE;
        gbc.gridheight = GridBagConstraints.RELATIVE;*/
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;    
        RottrPageViewPanel rottrPageViewPanel = new RottrPageViewPanel();
        JScrollPane jspPageView = new JScrollPane(rottrPageViewPanel,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(jspPageView, gbc);


        dim = new Dimension((int)dim.getWidth()-10, (int)dim.getHeight()-10);
        setPreferredSize(dim);
        setMaximumSize(dim);
    }
}
Attachments GridBagLayout.png 14.48 KB

gridheight and gridwidth are the number of columns/rows that this element should occupy in the "grid" defined by the GridBagLayout. It is not a pixel height.

So, so by setting

gbc.gridheight = 60;
        gbc.gridy = 0;

you are saying this element should run from gridy 0 to gridy 59, but then you do

gbc.gridy = 1;

(still with a gridheight of 60 BTW) which puts the second element "under" the first.

Thanx masijade, removing gridheight solved issue. I wish that some section of API been written more clearly

Don't sweat it, GBL is just something you've got to play with (and make mistakes in). Trust me, I know! ;)

This question has already been answered. Start a new discussion instead.