0

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();
txtPanel.add(txtField);
frame.getContentPane().add(txtPanel, BorderLayout.SOUTH);
Attachments 500x500.png 13.42 KB 800x600.png 18.15 KB
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by harinath_2007
0

You have two solutions..

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

frame.setResizable(false);

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..

Edited by harinath_2007: some changes...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.