Hi, was wondering if someone could give me a quick hand/point out the obvious please?
I'm trying to position 3 JPanels in a 'T' shape, with a toolbar across the top, and two other panels below sharing the horizontal space equally and filling 90% of the vertical space. The lefthand JPanel (formPanel) has a few label and TextField components, and the right has a TextArea.
If I just use empty JPanels there's no problem, the space is shared equally. If I add one custom panel containing multiple components on either side, the side that they are on takes up more than 50% of the horizontal space. However with just the TextArea JPanel on one side or other, the split is 50/50.
I've rewritten the code (and removed both the TextArea and FormPanel for simplicity) to try and demonstrate the problem in as short a space as possible. Let me know if you can't replicate it with just the Toolbar, it should be a cut and paste job.
I'm sure the answer is simple, but I'm quite new to GridBag. I'm trying to use the oracle docs, but it's pretty poorly described for a beginner, there's a lot of assumed knowledge required. I'm going to stick with it but if anyone knows of a good guide or book on the subject I'd appreciate it! **Edit: Core Java II by Horstmann and Cornell is one to go for?
What about a box layout for the lower part of the frame, with horizontal alighment and a bit of space in the middle? Only I have forgotten what the space is called. Maybe glue. Read about box layout in the Java® Tutorials.
BoxLaoyut respects preferredSize and maximumSize, so wouldn't fit the bill.
Space can be added using a horizontal/verticalStrut or a rigidArea; horizontal/verticalGlue expands to fill any remaining space and can be useful for e.g. right-aligning a JMenu on a JMenuBar (which has a default BoxLayout).
There are no new questions, but there may be new answers.
posted 3 years ago
thanks guys - i probably should've mentioned though that I previously used a borderlayout and it worked fine.
i was trying to replicate the layout in gridbag so that i could practice with that manager!
RE: preferred and maximum sizes, it's why i've put arbitrary borders around the internal components so i can see if any of them are forcing the containing panel to grow. i find it odd that the Toolbar is forcing the first grid to take up proportionately more space, when it only contains two small buttons aligned on the left hand side.
i'm currently doing more reading on the topic, so hopefully will come to an answer!