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

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

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

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

Ads









Related Tutorials/Questions & Answers:
How to add image in panel as background in net beans IDE?
How to add background image to div using CSS?
Advertisements
how to set background image
how to add panel inside frame?
how to get the image of a selected JRadioButton to another panel?
how to use a image in background in your application form?
net beans
net beans
net beans
net beans
net beans
net beans
set background image in javafx
NET BEANS
how to create menubar and the below background color/image in java swing
how to run audio files in net beans using j2me
Jmagick how to add image on an existing image
UIToolBar background image
UIView Background Image
UITableViewCell background image
UIButton background image
net beans
UITableView Background Image
net beans
net beans
net beans
UITextField Background Image
Background image UIBarButtonItem
background
uinavigationcontroller background image
in my project, i have to add scrollbars to a panel,. i need some example on it,how to doit.
how to generate PDF file using JSP with net beans
net beans 4
ModuleNotFoundError: No module named 'aldryn-background-image'
ModuleNotFoundError: No module named 'aldryn-background-image'
ModuleNotFoundError: No module named 'django-background-image'
How to change background, change background
in my project, i have to add only vertical scrollbar to a panel,but not horizontal scrollbar. i need some example on it,how to doit.
ModuleNotFoundError: No module named 'idec'
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
How can i Change Button Label Value Randomly in VIRTUAL KEYBOARD using JAVA or Net Beans ???
Setting a Background image for UITableView in iPhone & iPad application.
How to design a background, design a background, a background
add image in a row of table
add image in a row of table
JSP Background Image
jsp directory created in net beans but not able to access
Where is servlet log file in net beans?
Add color to background but I can't labels or textfields
ModuleNotFoundError: No module named 'idem'

Ads