title: How to set the width of a JTextField at runtime?
body: <p>Can someone please help me how to set the width of a <code>JTextField</code> at runtime? I want my text field to be resized on runtime. It will ask the user for the length, then the input will change the width of the text field. </p>
  
  <pre><code>if(selectedComponent instanceof javax.swing.JTextField){
      javax.swing.JTextField txtField = (javax.swing.JTextField) selectedComponent;
      //txtField.setColumns(numInput); //tried this but it doesn't work
      //txtField.setPreferredSize(new Dimension(numInput, txtField.getHeight())); //also this
      //txtField.setBounds(txtField.getX(), txtField.getY(), numInput, txtField.getHeight()); 
      //and this
      txtField.revalidate();
  }
  </code></pre>
  
  <p>I am using <code>null</code> layout for this, since I'm on edit mode.</p>