Can you tell me how to do like below in JAVA SWING.
Asked
Active
Viewed 3,725 times
0
-
Is the image really _in_ the text field, or is a a label _next to_ the text field? – tobias_k Sep 11 '13 at 09:53
-
http://harryjoy.com/2012/07/14/jtextfield-with-image-inside-it/ – Azodious Sep 11 '13 at 09:55
3 Answers
2
JTextField textField = new JTextField() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int y = (getHeight() - image.getHeight())/2;
g.drawImage(image, x0, y, this);
}
};

Nambi
- 11,944
- 3
- 37
- 49
1
Build a custom component.
Take a look at http://gmigdos.wordpress.com/2010/03/30/java-a-custom-jtextfield-for-searching/

René Link
- 48,224
- 13
- 108
- 140
-
While link only answers are allowed it is good idea to provide main content to answer in case link will change. – Pshemo Sep 11 '13 at 09:59
0
Read this tutorial. He does exactly what you're trying to do: http://harryjoy.me/2012/07/14/jtextfield-with-image-inside-it/

Harry Joy
- 58,650
- 30
- 162
- 207

cutmancometh
- 1,677
- 3
- 20
- 28