Decorating a JTextField with an image and hint

前端 未结 2 2008
轮回少年
轮回少年 2020-12-14 13:04

I\'m trying to create some nicer looking JTextFields with an image and a hint. To do this I made a decorator that overrides the paintComponent method. The reason I used a de

2条回答
  •  不思量自难忘°
    2020-12-14 13:48

    Text Prompt works with a JPasswordField.

    One difference is that the displayed icon disappears when text is entered. If you want the icon to be permanent then I suggest you create a custom "IconBorder* class to paint an Icon rather then do custom painting in the paintComponent() method.

    You approach will not work unless you duplicate the code for both JTextField and JPasswordField.

    Edit:

    Actually you don't need to create a custom IconBorder. The MatteBorder supports the painting of an Icon in a Border.

提交回复
热议问题