GridBagLayout
Well I managed to get my GridBagLayout to work exactly as I wanted in my java app, but when I converted it to an applet, I cant seem to get it to work
Essentially I have 3 methods which return a JPanel. I have topPanel (which is on the top and spans the entire width), addStatPanel (which is below the topPanel and to the left) and sigPanel (which is below topPanel and to the right)
In html this is what it would look like
<table border="1">
<tr>
<td colspan="2">topPanel()</td>
<tr>
<tr>
<td>addStatPanel()</td>
<td>sigPanel()</td>
</tr>
</table>
And thats how I got it to work in my app. This is my code I have in my applet, and I'm not sure where its going wrong. Only topPanel() and addStatPanel() show. If I remove addStatPanel(), sigPanel() will show.
package statsigs;
import java.awt.*;
import javax.swing.*;
publicclass MainApplextends JApplet{
private JPanel p_topPanel, p_addStatPanel, p_sigPanel;
private JButton b_chooseBackground, b_chooseColor;
private JList lst_stats;
private String[] stats =new String[1];
publicvoid init()
{
stats[0] = getParameter("username");
setLayout(new GridBagLayout());
GridBagConstraints c =new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
c.fill = c.REMAINDER;
add(topPanel(), c);
c.gridx = 0;
c.gridy = 1;
add(addStatPanel(), c);
c.gridx = 1;
c.gridy = 1;
add(sigPanel(), c);
setSize(500, 500);
}
private JPanel topPanel()
{
p_topPanel =new JPanel();
b_chooseBackground =new JButton("Select Background");
p_topPanel.add(b_chooseBackground);
b_chooseColor =new JButton("Select Font Color");
p_topPanel.add(b_chooseColor);
return p_topPanel;
}
public JPanel addStatPanel()
{
p_addStatPanel =new JPanel();
//Create a new JList which contains the parameters passed in at runtime
lst_stats =new JList(stats);
//Using the Decorator Pattern, add a ScrollPane to the JList
JScrollPane sp_scroller =new JScrollPane(lst_stats);
sp_scroller.setPreferredSize(new Dimension(120, 200));
//Add the ScrollPane to the panel
p_addStatPanel.add(sp_scroller);
return p_addStatPanel;
}
public JPanel sigPanel(){
p_addStatPanel =new JPanel();
JLabel hello =new JLabel("Hello!");
p_addStatPanel.add(hello);
return p_addStatPanel;
}
publicvoid start(){
System.out.println("Applet starting.");
}
publicvoid stop(){
System.out.println("Applet stopping.");
}
publicvoid destroy(){
System.out.println("Destroy method called.");
}
}
Thanks.

