I have a JPanel that looks something like this:
JPanel
JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); ... pane
If you want the width to keep changing, just keep it set to MAX INT. So...
textField.setMaximumSize( new Dimension(Integer.MAX_VALUE, textField.getPreferredSize().height) );