Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

How can i set the frame background to a picture in netbeans IDE?
i try to do it by setting icon for jlabel but it is not working?i got the jframe in small size(not actual one).the image is not visble


i also try to do it buy jpanel.it also have same effect.
Please give a solution.
Posted

1 solution

You will need to draw the image yourself by overriding the paintComponent(Graphics g) method of JComponent in your JFrame implementation. See the javadoc[^] for details

Java
@Override
protected void paintComponent(Graphics g)
{
    Image img = getToolkit().getImage("filename.png");
  //Image img = getToolkit().getImage(getClass().getResource("resource.png"));

    //draw image scaled to fit the entire size
    g.drawImage(img,0,0,getWidth(),getHeight());
   
}


As an alternative, for image manipulation you can use the Graphics2D[^] class.

Good Luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900