Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-14-2008, 05:04 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Add an image to JFrame
Hi all,

I want to add an image to a JFrame as the background. On top of that I want to working on more controls.

How can I do that, I work on Netbeans for this.

Eranga.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 13, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-14-2008, 05:38 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class ImagePanel extends JPanel { BufferedImage image; public ImagePanel(BufferedImage image) { this.image = image; } protected void paintComponent(Graphics g) { super.paintComponent(g); // Draw image centered. int x = (getWidth() - image.getWidth())/2; int y = (getHeight() - image.getHeight())/2; g.drawImage(image, x, y, this); } public static void main(String[] args) throws IOException { String path = "images/reindeer.jpg"; BufferedImage image = ImageIO.read(new File(path)); ImagePanel contentPane = new ImagePanel(image); // You'll want to be sure this component is opaque // since it is required for contentPanes. Some // LAFs may use non-opaque components. contentPane.setOpaque(true); contentPane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(5,5,5,5); gbc.weightx = 1.0; gbc.weighty = 1.0; // Add components. for(int j = 0; j < 8; j++) { gbc.gridwidth = ((j+1)%2 == 0) ? GridBagConstraints.REMAINDER : GridBagConstraints.RELATIVE; contentPane.add(new JButton("button " + (j+1)), gbc); } JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(contentPane); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-14-2008, 09:24 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Thanks a lot pal. It's really nice work.

I've done interesting thing here pal. Just add a JPanel on top of the JFrame. Then drag all the components onto it. On JPanel add a image icon in form load event.

Seems it's fine.

Eranga
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 13, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
GUI... setting my background to an image, im using a JFrame newtojava7 New To Java 2 03-24-2008 06:29 AM
JFrame problem vassil_zorev AWT / Swing 1 01-25-2008 03:53 AM
Converting multiple banded image into single banded image... Image enhancement archanajathan Advanced Java 0 01-08-2008 06:29 PM
can display image in JFrame? xCLARAx AWT / Swing 4 07-26-2007 04:33 PM
Help with JFrame Albert AWT / Swing 2 07-04-2007 05:44 AM


All times are GMT +3. The time now is 10:14 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org