In my Java Swing application i want to put a lock image inside a JTextField that is not editable, to appear like this :

I have created a JTextField, and inserted a JLabel above it and defined the lock icon for the JLabel. If the JTextField is editable then the JLabel appears fine as the image above shows, but if the JTextField is not editable then the image does not appear at all.
How can i fix that ?
You can try to add both label (for icon) and the textfield in a panel. Remove border from the textfield and add a common border around the panel. Set background to be the same as the textfield’s background.