Click on icon in a JTextField and clear its content
I am trying to create a JTextField with an image and a hint. The function of the textfield is a search field to search some books. Now, I like to go a little bit further. I would like to give the image a function. For example, if I click on the image the text in the textfield should be cleared. To achieve this implementation I created a new class and extended it with JTextField. This is the code: public class JSearchTextField extends JTextField implements FocusListener { /** * */ private static final long serialVersionUID = 1L; private String textWhenNotFocused; private Icon icon; private