If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 11: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

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