954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Modified JTextField did not show up in Applet?

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?

dineshswamy
Light Poster
29 posts since Feb 2010
Reputation Points: 10
Solved Threads: 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?

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

yes image didnt show up!!! text field appears

dineshswamy
Light Poster
29 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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

zeroliken
Veteran Poster
1,106 posts since Nov 2011
Reputation Points: 201
Solved Threads: 162
 

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.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: