Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT How to add image in panel as background in net beans IDE?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mannamchandra
How to add image in panel as background in net beans IDE?
1 Answer(s)      3 years and 11 months ago
Posted in : Swing AWT


How to add image in panel as background in net beans IDE?


Advertisement
View Answers

January 13, 2011 at 4:36 PM


Hello Friend,

Try the following code:

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.event.*;
import javax.swing.*;

public class BackgroundImage{
public static void main(String[] args) {
JFrame frame = new JFrame("");
frame.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Window win = e.getWindow();
win.setVisible(false);
win.dispose();
System.exit(0);
}
} );

JTextArea area=new JTextArea(15,4){

ImageIcon image = new ImageIcon( "C:/lily.gif" );

public void paint( Graphics g ) {
Dimension d = getSize();
for( int x = 0; x < d.width; x += image.getIconWidth() )
for( int y = 0; y < d.height; y += image.getIconHeight() )
g.drawImage( image.getImage(), x, y, null, null );
super.paint(g);
}
};

area.setOpaque(false);

JScrollPane sp = new JScrollPane( area );
frame.getContentPane().add( sp );

frame.setSize(300,100);
frame.show();
}
}

Thanks



Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com