How to get JTextField to stretch across pane in GridBag
807606Apr 14 2007 — edited Apr 14 2007I'm just learning this layout, and I can't seem to make a text field stretch across the entirety of the JFrame. It only stays within the first column, and worse yet, it makes that column larger than the others.
My goal is:
one text field for i/o all-the-way across the top, with 4 evenly sized buttons underneath. Stretching the window should evenly grow all fields and buttons (though text doesn't absolutely have to get taller, just wider).
My relevant code is:
public static void main (String[] args)
{
JFrame c1 = new JFrame("test");
c1.setSize(200,200);
Container pane = c1.getContentPane();
pane.setLayout(new GridBagLayout());
c1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c1.setVisible(true);
c1.setResizable(true);
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
JTextField numFld = new JTextField(20);//i/o field
//numFld.setColumns(30);
c.gridwidth=4;
c.weightx=1;
c.weighty=1;
c.gridx=0;
c.gridy=0;
pane.add(numFld);