The Java Swing package library has a class called "JTextField" which is used to create a single line input field in a graphical user interface. The "getText" method retrieves the text currently entered in the input field.
Example 1:
JTextField username = new JTextField(20); //Creates a text field of 20 characters String enteredText = username.getText(); //Retrieves the text entered in the text field
Example 2:
JTextField search = new JTextField("Enter keyword"); //Creates a text field with the default text "Enter keyword" search.addMouseListener(new MouseAdapter() { //Adds a mouse listener to clear the default text when clicked public void mouseClicked(MouseEvent e) { search.setText(""); } }); String searchTerm = search.getText(); //Retrieves the text entered in the search field
In both examples, the "getText" method is used to retrieve the text currently entered in the JTextField. The Swing package library is used to create the user interface components.
Java JTextField.getText - 30 examples found. These are the top rated real world Java examples of javax.swing.JTextField.getText extracted from open source projects. You can rate examples to help us improve the quality of examples.