tags:

views:

11

answers:

1

Simply put, I would like to make java do what I want but I can not get my head around the layout manages for anything other that auto resizing to what it feels like doing.

All I would like is a fixed height "footer" and the top "main" area to auto resize in height to whatever the window is.

With the horizontal for both having a min size but no max size.

Is it possible (I know it is but it feels like it isn't atm!)

Please help!

many thanks

Edit: Updated with advice from below:

    public JPanel getPanDescription()
    {
        JPanel masterPane = new JPanel();
        masterPane.setMaximumSize(new Dimension(999999,400));
        masterPane.setMinimumSize(new Dimension(100,400));
          <snip>
            return masterPane;
    }

this.panDescription = getPanDescription();

this.panPage = new JPanel(new BorderLayout());

this.panPage.add(this.searchPanel, BorderLayout.CENTER);
this.panPage.add(this.panDescription, BorderLayout.PAGE_END);

Works just fine, but depending on the content of panDescription, depends on its size. It still just resizes to the content :S

+2  A: 

Use a BorderLayout. Add your footer to the bottom location. Set the max size of the footer to the fixed height you want and a width bigger than your window will ever be.

JPanel mainPanel = new JPanel();
JPanel footerPanel = new JPanel();

this.setLayout(new BorderLayout());
this.add(mainPanel);
this.add(footerPanel, BorderLayout.SOUTH);

footerPanel.setMaximumSize(new Dimension(10000, 100));
footerPanel.setPreferredSize(new Dimension(600, 100));
footerPanel.setMinimumSize(new Dimension(1, 100));
Erick Robertson
Is there really no "as far as you can extend it" option? like -1 or even 0? I have to make up a max number? Java's a bit weird :lol:I'll give this a shot (it is actually what I'm trying to do atm already)
Dorjan
+1 for suggesting BorderLayout. But there is no need to set the maximum or minimum sizes. The BorderLayout ignores these values and will automatically stretch the panels width to fit the size of the frame. The preferred height of the panel is determined by the components added to it.
camickr
This isn't what is happening though, what Erick says holds more water but now I'm running into another issue which I'm sure is actually for a different question.
Dorjan
Is there a difference between JPanel and Panel?
Dorjan
Yes, but I meant to say JPanel, so I edited the answer.
Erick Robertson
Well then it doesn't work :( It still resizes as it wishes :( - i've added more above so you might see what is wrong.
Dorjan
Add the preferred size, too. The problem is that each layout manager type uses different things to determine what size components should be. Technically, it doesn't even have to honor any of these sizes. camickr used preferred size, maybe that's the one that's going on here.
Erick Robertson
Bloody java >.< Thank you, this is the answer I was looking for here :)
Dorjan