JTextField textField = new JTextField("Hello, World!"); textField.selectAll();
JButton selectAllButton = new JButton("Select All"); selectAllButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textField.selectAll(); } });In this example, we create a new JButton object with the label "Select All" and use an anonymous inner class to create an ActionListener for the button. When the button is clicked, it calls the selectAll() method on the textField object to highlight all the text in the field. Package Library: The package library for javax.swing.JTextField and selectAll() method is javax.swing.*.