I'm really struggling with creating a complicated layout. Here is a picture of what I want in the end:
(source: fbcdn.net)
I've attempted to divide and conquer, creating small panels and putting those in other panels. At first I figured a borderlayout for the main container panel which is in the initial JFrame, with a bunch of GridBagLayouts for the details in those panes. When that wasn't working, I figured I would try my hand at an all out GridBagLayout. Right now my goal is to get the top group of character and location panels/cards to be displayed in their correct aspect ratio (about 4:3) and have them resize correctly (maintaining aspect ratio as best as possible) as the window is resized. What I am getting is a super small square panel for each card when the window first comes up. I want them to start in the aspect ratio (4:3) to begin with.
Am I going about this correctly?
Should I stick with all GridBagLayouts?
If not, what combinations of layouts do you see that may work?
Lastly and probably most importantly, how come they do not start out with the correct gridwidth or gridheight?
It would be nice if all the cards maintained a 4:3 or 3:4 aspect ratio when the window is near a 4:3.
public class OverPower {
public static void main(String[] args) {
JFrame table = new JFrame();
table.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
table.setLayout(new BorderLayout());
JPanel contentPane = new OppCharsPanel();
table.setContentPane(contentPane);
table.setLocationByPlatform(true);
table.pack();
table.setLocationRelativeTo(null);
table.setVisible(true);
}
}
public class OppCharsPanel extends JPanel {
public OppCharsPanel() {
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(20, 15, 20, 15);
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = 4;
gbc.gridheight = 3;
gbc.weightx = 4.0;
gbc.weighty = 3.0;
//back row
gbc.gridx = 4;
gbc.gridy = 0;
JPanel oppHomebase = new JPanel();
oppHomebase.setBackground(Color.RED);
this.add(oppHomebase, gbc);
gbc.gridx = 8;
gbc.gridy = 0;
JPanel oppReserve = new JPanel();
oppReserve.setBackground(Color.RED);
this.add(oppReserve, gbc);
//front row
gbc.gridx = 0;
gbc.gridy = 3;
JPanel oppBattlesite = new JPanel();
oppBattlesite.setBackground(Color.RED);
this.add(oppBattlesite, gbc);
gbc.gridx = 4;
gbc.gridy = 3;
JPanel oppChar1 = new JPanel();
oppChar1.setBackground(Color.RED);
this.add(oppChar1, gbc);
gbc.gridx = 8;
gbc.gridy = 3;
JPanel oppChar2 = new JPanel();
oppChar2.setBackground(Color.RED);
this.add(oppChar2, gbc);
gbc.gridx = 12;
gbc.gridy = 3;
JPanel oppChar3 = new JPanel();
oppChar3.setBackground(Color.RED);
this.add(oppChar3, gbc);
}
}