JTextField textField = new JTextField(); textField.setPreferredSize(new Dimension(200,30));
JTextField textField = new JTextField("Enter some text here"); textField.setPreferredSize(new Dimension(150,20));In this example, we create a new JTextField object with some initial text and set its preferred size to 150x20 pixels. These examples help to customize the size of the text field to fit the specific needs of the GUI application. The javax.swing package is a part of the Java Standard Library.