JAVA SWING CODE TO DISPLAY IMAGE IN JTextField

/*
         Author : RK
*/

import java.awt.*;
import javax.swing.*;

class ImgInTField extends JFrame
{
public ImgInTField()
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p=new JPanel(new BorderLayout());
JTextField tf=new JTextField(5);
JLabel label=new JLabel(new ImageIcon(“Img.gif”));
label.setOpaque(true);
label.setBackground(tf.getBackground());
label.setPreferredSize(new Dimension(label.getPreferredSize().width,tf.getPreferredSize().height));
p.setBorder(tf.getBorder());
tf.setBorder(null);
p.add(label,BorderLayout.WEST);
p.add(tf,BorderLayout.CENTER);
JPanel p1=new JPanel();
p1.add(p);
getContentPane().add(p1);
pack();
setLocationRelativeTo(null);

}
public static void main(String RK[])
{
ImgInTField obj=new ImgInTField();
obj.setVisible(true);
obj.setSize(100,100);
}

}

Advertisements

About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in J2SE. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s