0

dont know the why this modified JTextField did not show up..help me out

import java.awt.*;
import javax.swing.*;
public class JBgtextfield extends JTextArea{

	public void paint(Graphics g)
	{
	setOpaque(false);
	ImageIcon ic=new ImageIcon("image1.png");
	Image i=ic.getImage();
	g.drawImage(i,0,0,this);
	super.paint(g);
	}
}

i then created an instance of this class and added it to a panel in init() method. but it didnt show up?

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

Do you mean the text field didn't show up, or it did show up but the image was missing? If you paint a small colored rectangle instead of the image does that work?

0

is the image found in the same directory or in the right path?

Edited by zeroliken: n/a

0

new ImageIcon(...) is famous for not throwing any exceptions when it fails to find the file; it's just empty. JLabel is happy to accept null for its image icon, so the final result is no image and no error messages. We see that quite often in DaniWeb "help!" posts.
Use the exists() method of the File class with the path/name of the file to confirm that your program can find the file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.