background

background

how to add image as background to a frame

View Answers

February 8, 2011 at 3:33 PM

Java Swing Background Image

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

public class BackgroundImage1{
private BufferedImage image;
private JPanel panel = new JPanel(new GridLayout(4,2)) {
protected void paintComponent(Graphics g){
super.paintComponent(g);
if(image != null){
g.drawImage(image, 0, 0, this);
}
}
};
public BackgroundImage1(){
try{
File file=new File("C:\\rose.jpg");
image = ImageIO.read(file);
Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
panel.setPreferredSize(imageSize);
JLabel label1=new JLabel("Username: ");
JLabel label2=new JLabel("Password: ");
JTextField text1=new JTextField(10);
JTextField text2=new JTextField(10);
JButton b1=new JButton("Login");
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(b1);
}
catch(Exception e){}
}
public JPanel getPanel(){
return panel;
}
public static void main(String[] args){
JFrame frame = new JFrame("BackgroundImage ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new BackgroundImage1().getPanel());
frame.setSize(300,150);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}









Related Tutorials/Questions & Answers:
background
background  how to add image as background to a frame
background image
background image  how to set background image in jsp using netbeans IDE 6.9
Advertisements
GRADIENT BACKGROUND
GRADIENT BACKGROUND  How to set gradient colors a s background for a jframe? pls help me..............   http://www.roseindia.net/java/example/java/swing/GradientColor.shtml
How to design a background, design a background, a background
How to design a background       If you don't have background, don't worry because you will learn here how to design a background by this example. New File: Take a new file.ADS
How to change background, change background
How to change background       This example will teach you to change background of any object... of the another picture to make background picture. Paste: Go to Edit menu > Paste
picture in background in a HTML
picture in background in a HTML  How is picture displayed in background in a HTML
HTML background images
HTML background images  How can I specify background images
UIToolBar background image
UIToolBar background image  Hi, How to set background image of UIToolBar? Give me code for adding UIToolBar's background image. Thanks
uiscrollview background color
uiscrollview background color  Is it possible to set the uiscrollview background color in iPhone application
HTML document's background color
HTML document's background color  How to set a HTML document's background color
UIButton background image
UIButton background image  Hi, How to create uibutton with background image? Thanks
div background color in html
div background color in html   How to change the background color of DIV in HTML
ModuleNotFoundError: No module named 'background'
ModuleNotFoundError: No module named 'background'  Hi, My Python... 'background' How to remove the ModuleNotFoundError: No module named 'background' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'background'
ModuleNotFoundError: No module named 'background'  Hi, My Python... 'background' How to remove the ModuleNotFoundError: No module named 'background' error? Thanks   Hi, In your python environment you
background images in css not working
background images in css not working  In the application i'm passing a background image from CSS in the given format ... background-image: url... of adding background images in css
UITableView Background Image
UITableView Background Image  How to set an image as a background of UITableView in iPhone SDK   I think, we can't
Jbutton[] background & foregroundcolor change
Jbutton[] background & foregroundcolor change  how to change... foreground and background color is changed. the remaining jbutton foreground and background color are not changed. next i select button[9] then the button[5] foreground
UITextfield Background Color
UITextfield Background Color  In my iPhone application, i am using... is ..it's showing a background color. Though my text field color is white. Can you please suggest.. , how can i remove the background color of text field. Thanks!  
UIView Background Image
UIView Background Image  HI, Please let's know how to add background image to a view? Thanks   Hi You can use the following code...:@"myimage.png"]]; Read more at UIView Image Background Tutorial page. Thanks
div style background
div style background  How to add background color to a div? What is the code of div style background?   Hi, You can use the following code: <div style="background-color: #ccffcc;"> <p>Content</p> <
how to set background image
how to set background image  how to set image in background in that image i want over lay text how it possible in jsp? using flash image how it is overlayed in jsp page? thanks
changing uiview background color
changing uiview background color  changing UIView background color in ios   self.view.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:230.0f/255.0f blue:183.0f/255.0f alpha:1.0f
UITableViewCell background image
UITableViewCell background image  Hi, I am developing UITable based iPhone application. I have to add the background image to UITableViewCell. Please tell me how to add UITableViewCell background image. Thanks   Hi
set background image in javafx
set background image in javafx  Hi, How to add backgroung image in javafx integrated with jswing
Background image UIBarButtonItem
Background image UIBarButtonItem  i wanted to add a background image to my UIBarButtonItem.. that i created into .xib in my iPhone application.   Set the background image to UIBarButtonItem UIBarButtonItem *btn
jframe background color not showing
jframe background color not showing  jframe background color is not showing. please suggest.   Just add the background color to JPanel and then add it to JFrame. For example .. JFrame myFrame = new JFrame(); JPanel
uinavigationcontroller background image
uinavigationcontroller background image  I wants to add a background... a background image to uinavigationcontroller... the Background Image to it as given belowâ?¦ #import <UIKit/UIKit.h> #import <
UITextField Background Image
UITextField Background Image  How can i set a background image on UITextField. I have placed that UITextField on UIToolBar.   Code to Set a Background Image on UITextField - (void)viewDidLoad { [super viewDidLoad
JList Background Images..Urgent
JList Background Images..Urgent  I has done a JList that can change background color when i selected each of it, but if i want to change background image rather than background colors, how can i do it? Please help! my previous
HTML - table background color.
HTML - table background color. Description : Here, you will see how to specifies the table back ground color in html page. The <table > is a html... the background color of table.  Code : <!DOCTYPE html PUBLIC "
How to make a chrome background, make a chrome background, chrome background
How to make a chrome background     ... background so follow all the steps as given in this example. New Document: First take a new document with any color background and fill "White" color
ModuleNotFoundError: No module named 'background-rm'
ModuleNotFoundError: No module named 'background-rm'  Hi, My... 'background-rm' How to remove the ModuleNotFoundError: No module named 'background-rm' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'background-mask'
ModuleNotFoundError: No module named 'background-mask'  Hi, My... named 'background-mask' How to remove the ModuleNotFoundError: No module named 'background-mask' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sx-background'
ModuleNotFoundError: No module named 'sx-background'  Hi, My... 'sx-background' How to remove the ModuleNotFoundError: No module named 'sx-background' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'background-mask'
ModuleNotFoundError: No module named 'background-mask'  Hi, My... named 'background-mask' How to remove the ModuleNotFoundError: No module named 'background-mask' error? Thanks   Hi, In your python
Javascript background color - Java Beginners
Javascript background color  Hi How to compare background color...; Hi Friend, If you want to change the background color of the textbox, try the following code: Change background Color function check
Setting bootstrap container background color
Setting bootstrap container background color  How to set the background color of the container in bootstrap for a web page? Thanks   Hi, You can set the color using the following code: body { background-color
background
Changing background color using JavaScript
Changing background color using JavaScript  Hi Sir Is there any way to change the background color using JavaScript ? Please mention code with your... below function to change the background color & call it wherever it needed
UIWebView Background Color
UIWebView Background Color If you wanted to change the background color on UIWebView in iPhone SDK, then you required to set the background color of UIWebView...). Where as setBackgroundColor will allow you to change the color of background area
Javascript change textbox background
Javascript change textbox background In this section, you will learn how to change the background of textbox. Here we have created a textbox and allowed...' then the background changed to green otherwise it will remains red. Here is the code
Background Image for Navigation Bar
Background Image for Navigation Bar The tutorial illustrates how to add background image for UINavigationBar. To add a background image to UINavigationBar, you need to create a category that extends UINavigationBar. Just find the below
Photoshop Tutorial :background image
Make a Bullet Background       This example is about a bullet background, normally you use background... own background image. So let's try. Take a new file: Go to file menu and click
how to use a image in background in your application form?
how to use a image in background in your application form?  how to use a image in background in your application form
changing Background Color
changing Background Color   ... change background color of a pdf file. You can change the background color... color) to set the background color of that chunk. Here we pass
pdf background color
pdf background color      ... the background of the pdf file as well as the size of a pdf file irrespective of the fact... the background of the pdf file which you have built. To make a program over
How to design a beautiful background with flowers, design a beautiful background with flowers, beautiful flowers background
How to design a beautiful background with flowers  ... to design a beautiful background of the flowers. New File: Start... file to make flower background. Fill: Go to File Menu > Fill, choose your
we make a picture as a background on my web pages
we make a picture as a background on my web pages  How do we make a picture as a background on my web pages
adding background image - Java Beginners
adding background image  how do i add background image to this code... = new JTextField (""); int average; JPanel background = new JPanel...); background.add(text11); getContentPane().add(background
Photoshop change a background image
Photoshop: change a background image   ... to change the background of an image. If you want to try this then this tutorial... in which you want to change the background image. I have selected an image

Ads