Ive been trying to make adjust my display the way i want it, but it doesnt seem to work. I want to use GridBagLayout to make something like this:
I want to sort panels like this
Ive found a piece of code, and edited it:
public class GBLPanel extends JPanel
{
private static final long serialVersionUID = 1L;
GridBagConstraints gbc = new GridBagConstraints();
public GBLPanel(Dimension appdim)
{
GridBagConstraints c = new GridBagConstraints();
setLayout(new GridBagLayout());
add(gbcComponent(0,0,2,1,0,0), gbc);
add(gbcComponent(0,1,1,1,0,50), gbc);
add(gbcComponent(1,1,1,1,0,50), gbc);
}
private JPanel gbcComponent(int x, int y, int w, int h, int ipadyx, int ipadyy){
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.ipadx=ipadyx;
gbc.ipady=ipadyy;
gbc.fill = GridBagConstraints.BOTH;
JPanel panel = new JPanel();
JTextField text = new JTextField("(" + w + ", " + h + ")");
panel.setBorder(new TitledBorder("(" + x + ", " + y + ")"));
panel.add(text);
return panel;
}
}
and i cant figure out how to shape it as i want, anyone can help ? Thanks very much !

A
BorderLayoutwould probably be easier to do this for you.But if you want/need to use a
GridBagLayout, the current problem you are having is that you are setting theweightfor both x and y for each panel to 1. Meaning they will all be distributed evenly.Try changing them to reflect the values you want by doing something like this