JTextField textField = new JTextField(); textField.setColumns(20);
JPanel panel = new JPanel(); JTextField textField = new JTextField(); textField.setColumns(10); panel.add(textField);This code creates a new JPanel and adds a text field component to it. The width of the text field is set to 10 columns. Package library: javax.swing.