I know I already asked this question, but due to my mistake in the example code and failure to actually ask the question, first few hours have passed and I rarely get any new comments or answers to older questions. The original was deleted.
I used this code to generate the window below (well, everything that is within the orange rectangle, to be exact):
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(Color.YELLOW);
setFixedSize(new Dimension(LayoutConstants.PAGE_WIDTH + 2*LayoutConstants.HALF_SPACE_BETWEEN_PAGES, LayoutConstants.PAGE_HEIGHT + 2*LayoutConstants.HALF_SPACE_BETWEEN_PAGES));
setBorder(BorderFactory.createLineBorder(Color.ORANGE, LayoutConstants.HALF_SPACE_BETWEEN_PAGES));
JPanelSize header = new JPanelSize();
header.setBackground(Color.RED);
header.setSize(new Dimension(LayoutConstants.PAGE_WIDTH, LayoutConstants.HEADER_HEIGHT));
add(header);
elementContainer = new JPanelSize();
elementContainer.setLayout(new BoxLayout(elementContainer, BoxLayout.Y_AXIS));
elementContainer.setBackground(Color.GREEN);
elementContainer.setFixedSize(new Dimension(LayoutConstants.CONTENT_WIDTH, LayoutConstants.CONTENT_HEIGHT));
add(elementContainer, BorderLayout.CENTER);
JPanelSize footer = new JPanelSize();
footer.setBackground(Color.MAGENTA);
footer.setFixedSize(new Dimension(LayoutConstants.PAGE_WIDTH, LayoutConstants.FOOTER_HEIGHT));
add(footer);
This is JPanelSize class, which simplifies my life immensely:
import java.awt.Dimension;
import javax.swing.JPanel;
public class JPanelSize extends JPanel
{
private static final long serialVersionUID = 1L;
public void setFixedSize(Dimension size)
{
setMinimumSize(size);
setPreferredSize(size);
setMaximumSize(size);
}
}
And this is the result:
Header and footer should fill the yellow area while the green JPanel should be centered. Heights are all fine.
I'm overriding set(...)Size() methods because I'm simulating an A4 here.
What am I doing wrong?