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 04-16-2008, 05:57 PM
Floetic's Avatar
Member
 
Join Date: Feb 2008
Location: Belfast, Northern Ireland, UK
Posts: 7
Floetic is on a distinguished road
Send a message via MSN to Floetic
Center background image
Hi!

The background image is showing but I would like to center it - how can this be done!?!

Thanks.


Code:
import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import javax.swing.*; public class NewClass10 extends JPanel { final BufferedImage bi; public NewClass10() throws IOException { bi = ImageIO.read(new File("C:\\Documents and Settings\\Flo\\My Documents\\My Pictures\\bigstockphoto_Binary_Globe_55596.jpg")); } public void paintComponent(Graphics g) { g.drawImage(bi,getWidth()-bi.getWidth(),getHeight()-bi.getHeight(),null); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); NewClass10 t7 = new NewClass10(); f.setContentPane(t7); f.setSize(1025,703); f.setVisible(true); } catch (IOException ioe) { ioe.printStackTrace(); } } }); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-24-2008, 06:50 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
int x = (getWidth()-bi.getWidth())/2; int y = (getHeight()-bi.getHeight())/2; g.drawImage(bi, x, y, null);
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
center a form tommy New To Java 2 08-06-2007 09:47 PM
Background image in java toby AWT / Swing 1 07-29-2007 08:15 AM
Why this image background is black ? samson Java 2D 1 07-17-2007 05:24 AM
Help Center Live 2.1.3 JavaBean Java Announcements 0 07-06-2007 04:43 PM


All times are GMT +3. The time now is 04:23 PM.


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