Share on Google+Share on Google+

shweta
setbackground image to JFrame
1 Answer(s)      7 years ago
Posted in : Java Beginners
how to setbackground image to JFrame.

Ads

View Answers

April 22, 2010 at 12:11 PM


Hi Friend,

Try the following code:

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

public class TransparentBackgroundImage
{
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);
}
} );
JPanel panel=new JPanel(new GridLayout(2,2)){
ImageIcon image = new ImageIcon( "C:/rose.jpg" );
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);
}
};
JLabel l1=new JLabel("Name");
JLabel l2=new JLabel("Address");
JTextField text=new JTextField(20);
JTextField text1=new JTextField(20);
panel.setOpaque(false);
text.setOpaque(false);
text1.setOpaque(false);
panel.add(l1);
panel.add(text);
panel.add(l2);
panel.add(text1);
frame.add( panel );

frame.pack();
frame.show();
}
}

Thanks









Related Tutorials/Questions & Answers:
setbackground image to JFrame - Java Beginners
setbackground image to JFrame   how to setbackground image to JFrame... TransparentBackgroundImage { public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener( new WindowAdapter() { public
insert image in JFrame - Development process
= new JFrame("Display image"); Panel panel = new ShowImage...insert image in JFrame  how to insert a image in JFrame.please... Panel { BufferedImage image; public ShowImage() { try
Advertisements
Java Image On JFrame Title
How to set Image On JFrame In this section, you will learn how to set an image on JFrame title using Java program. For this, we have created an object...() that will load the specified image and the method setIconImage() of JFrame class
JFrame
JFrame  write an application with a JFrame that five labels describing reasons that a customer might not buy your product(for example "Too expensive") every time the user clicks a Jbutton, remove one of the negative reasons
jframe
jframe  Create a JFrame for the Summervale Resort. Allow the user to view the information about different rooms available, dining options and activities offered. Include at least two options in each menu and display appropriate
JFrame
Jframe. How can i do it. Please help me to do it. Or what else can i have
Refresh JFrame
Refresh JFrame  How to refersh a JFrame and its componets
Hiding a JFrame
javax.swing.*; import java.awt.event.*; class PassData extends JFrame { JTextField... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
Hiding a JFrame
javax.swing.*; import java.awt.event.*; class PassData extends JFrame { JTextField... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
how to add scrollbar to JFrame
i add my panel to scrollpane and then add that scrollpane to JFrame than...; /*********************************************************/ ImageIcon img; JLabel create,change,image,your,can; JComboBox cb...=getContentPane(); setBackground(Color.white); img=new ImageIcon("googletitle.gif
how to add scrollbar to JFrame
i add my panel to scrollpane and then add that scrollpane to JFrame than...; /*********************************************************/ ImageIcon img; JLabel create,change,image,your,can; JComboBox cb...=getContentPane(); setBackground(Color.white); img=new ImageIcon("googletitle.gif
how to add scrollbar to JFrame
i add my panel to scrollpane and then add that scrollpane to JFrame than...; /*********************************************************/ ImageIcon img; JLabel create,change,image,your,can; JComboBox cb...=getContentPane(); setBackground(Color.white); img=new ImageIcon("googletitle.gif
how to add scrollbar to JFrame
i add my panel to scrollpane and then add that scrollpane to JFrame than...; /*********************************************************/ ImageIcon img; JLabel create,change,image,your,can; JComboBox cb...=getContentPane(); setBackground(Color.white); img=new ImageIcon("googletitle.gif
how to add scrollbar to JFrame
i add my panel to scrollpane and then add that scrollpane to JFrame than...; /*********************************************************/ ImageIcon img; JLabel create,change,image,your,can; JComboBox cb...=getContentPane(); setBackground(Color.white); img=new ImageIcon("googletitle.gif
how to reset JFrame
how to reset JFrame  how to reset JFrame
refresh checkbox jframe
refresh checkbox jframe  How to refresh checkbox button in JFrame
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
jumping frame jFrame to jInternalframe
jumping frame jFrame to jInternalframe  Afternoon sir, I want to ask... and sub menu(employee). in Form Login(jFrame) have username(textfield1) and password(passwordfield1), in Menu(jframe) have Menu employee(jMenu),creaby(jlabel1
Removing the Title Bar of a JFrame
Removing the Title Bar of a JFrame  How to remove the Title Bar of a JFrame in Swing Application?   Please check the tutorial Removing the Title Bar of a Frame for the source code and example description. Thanks
JFRAME - Java Beginners
javax.swing.*; import java.awt.event.*; public class MenuExample extends JFrame
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...("serial") public class AddPage extends JFrame { JDesktopPane pane = new
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... PrintExample extends JFrame implements ActionListener { public static void main...() { setBackground(Color.white); Font font = new Font("Serif", Font.PLAIN
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... PrintExample extends JFrame implements ActionListener { public static void main...() { setBackground(Color.white); Font font = new Font("Serif", Font.PLAIN
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir thanks a lot for your reply... this public class PrintExample extends JFrame implements ActionListener { public...() { setBackground(Color.white); Font font = new Font("Serif", Font.PLAIN, fontSize
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads