Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NetBeans IconImage

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I have a small problem with setting the IconImage of the JFrame with Swings. I tried to Hard code it N also tried using the Properties window. But it was not successful.
The code i wrote is as follows
try{
this.setIconImage(Toolkit.getDefaultToolkit().getImage("/Pic/ir.png"));
}
catch(Exception e)
{
e.printStackTrace();
}

And my Second Problem is with the JPanel. I have extended the JPanel and overrided the method PaintCOmponent to draw the Image with it. When i add this JPanel with the JFrame Image is not at all visible.

The Code is as follows.
/*
* WPanel.java
*
* Created on July 5, 2006, 1:39 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package Components;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JPanel;
import java.net.URL;
import java.awt.Image;

/**
*
* @author Ranganath.S
*/
public class WPanel extends JPanel{
private Image img;
/** Creates a new instance of WPanel */
public WPanel()
{

URL iUrl=getClass().getResource("/Pics/welcome.jpg");
img = Toolkit.getDefaultToolkit().getImage(iUrl);

}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(img,0,0,this);
}
}


Thank you
Regards
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic