Forums Register Login

Can't get my Gridbag Layout Components to display how I want

+Pie Number of slices to send: Send
Hi guys.

I have quite a specific view for how I want my components layed out. No matter what I try I can get them to display how I want! I'm using three JPanels. There's a main panel that goes inside the tabbed pane. This main panel contains two other panels. The First panel is a gridbaglayout panel, with labels on the left column, and components on the right column. The second panel is underneath the second, and contains a label, and a button beneath it. THis uses a basic box layout, with one component per line. The label doesn't always appear (depends if a component is changed). With everything showing, this is how it looks so far:



However, I want the Labels on the left of the pane. The right hand column should be aligned horizontally and have more space from the labels. Ideally I'd like a gap between the last label/checkbox and the Note label.

This is my current code for the panel/s inside the tabbed pane window.



Thanks for the help! Kind regards
1
+Pie Number of slices to send: Send
I would say the problem is the videoPanel. By default is uses a FlowLayout which defaults to center alignement. The second panel wraps to the second line only because there is not enough space on the first line. Try resizing the frame wider and the note panel will probably move to the top line.

Instead, you can just use a vertical BoxLayout. Note that you will probably need to use the setAlignmentX(...) method to left align the components in the BoxLayout.

Also, if you want a gap between compnents then you can add a "vertical strut" to the panel.

Read the section from the Swing tutorial on How to Use Box Layout for more information about the above two features.
+Pie Number of slices to send: Send
Hi, thanks for replying.

I'm not entirely sure changing the video panel would change the panel I wish to modify (panel 1) ?

THis is an image of what I'm trying to do. Each red square is a panel inside the videoPanel.

+Pie Number of slices to send: Send
I understand what you are trying to do and gave you a suggestion.

Did you verify the layout manager of your videoPanel? What happened when you tried my suggestion?
pie. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 528 times.
Similar Threads
Help with Layout issues
Buttons on CardLayout
GridbagLayout
Keyboard layout problem
GridBagLayout problems
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:12:51.