Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. 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 contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > How to set an image as background using Java on Netbeans

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-08, 12:30
db2learner2008 db2learner2008 is offline
Registered User
 
Join Date: Nov 2008
Posts: 23
How to set an image as background using Java on Netbeans

Hi Expert,
I am a newbies in java and i am trying to creat an image as a background on a GUI i created, but i am not getting any image dispalying as bacground. I need to connect this GUI on DB2:
Here is the code i have maybe someone can see where i am going wrong and then modify the code for me to get the image:
Code:
import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; public class NewClass3 { public static void main(String[] args) { ImagePanel panel = new ImagePanel(new ImageIcon("C:\\myimage.jpg").getImage()); JFrame frame = new JFrame(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } } class ImagePanel extends JPanel { private Image img; public ImagePanel(String img) { this(new ImageIcon(img).getImage()); } public ImagePanel(Image img) { this.img = img; Dimension size = new Dimension(img.getWidth(null), img.getHeight(null)); setPreferredSize(size); setMinimumSize(size); setMaximumSize(size); setSize(size); setLayout(null); } public void paintComponent(Graphics g) { g.drawImage(img, 0, 0, null); }

Can some help me please?
Thanks
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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