I am creating a simple GUI with a few buttons and a text field. I set the window size to to 500x500 and the text field fits on the South perfectly but once i resize the window the text field stays the same size is it possible to make to so when a user resizes the window the text field changes with it.

if you look at 500x500 pic the text field is good once I change it 800x600 pic the text field is does not reach bottom border.

private JTextField txtField;
txtField = new JTextField(37);
JPanel txtPanel = new JPanel();
frame.getContentPane().add(txtPanel, BorderLayout.SOUTH);

You have two solutions..

The first and simplest way would be set your jframe non-resizable. So user cannot resize window.


The second way would be make your jframe listen to window-resized events.

Then get the size of the window by

Dimension d=frame.getSize();
int x=d.getWidth();
int y=d.getHeight();
textField.setSize(x,y); //Or setbounds

So make modifications to the code according to your requirements..