How to set the width of a JTextField at runtime?
===

Can someone please help me how to set the width of a jtextfield on runtime? I want my textfield to be resized on runtime. It will ask the user for the length then the input will change the width of the text field. 

    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();
                        }