How to set the width of a JTextField at runtime?
问题 Can someone please help me how to set the width of a JTextField 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. 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())); /