• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Alex Gurr
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alex Gurr
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!