Replace:
JFrame.setIconImage(Image "img.jpg");
With:
this.setIconImage(new
ImageIcon(getClass().getResource("img.jpg")).getImage());
When you use JFrame.setIconImage(), it is looking for a static method on the
JFrame class which does not exist. The method is an instance method and
needs to be prefixed with an object reference such as "this". Ensure that
img.jpg is in the same directory as background.java.
Also, this method call needs to be inside the background() constructor, not
outside it as it currently is. Further, it's better to use the standard
Java naming conventions which stipulate use of a capitalised first letter
for class names.
HTH,
-JCT
> -----Original Message-----
> From: ankitraghu [mailto:
ankitraghu@...]
> Sent: Monday, 2 November 2009 13:35
> To:
nbusers@...
> Subject: [nbusers] How can I change the default icon of JFrame (java
> cup) to my desired image in netbeans
>
>
> Ankit wrote:
> >
>
> >
>
> > package extra;
>
> > import java.awt.Image;
>
> > import javax.swing.JFrame;
>
> >
>
> > public class background extends javax.swing.JFrame {
>
> >
>
> > /** Creates new form background */
>
> > public background() {
>
> > initComponents();
>
> > }
>
> > JFrame.setIconImage(Image "img.jpg"); // ????Here the Error
> occured
>
> >
>
> >
>
> > @SuppressWarnings("unchecked")
>
> > // <editor-fold defaultstate="collapsed" desc="Generated Code">
>
> > private void initComponents() {
>
> >
>
> >
> setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>
> >
>
> > javax.swing.GroupLayout layout = new
> javax.swing.GroupLayout(getContentPane());
>
> > getContentPane().setLayout(layout);
>
> > layout.setHorizontalGroup(
>
> >
> layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>
> > .addGap(0, 400, Short.MAX_VALUE)
>
> > );
>
> > layout.setVerticalGroup(
>
> >
> layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>
> > .addGap(0, 300, Short.MAX_VALUE)
>
> > );
>
> >
>
> > pack();
>
> > }
>
> > public static void main(String args[]) {
>
> > java.awt.EventQueue.invokeLater(new Runnable() {
>
> > public void run() {
>
> > new background().setVisible(true);
>
> > }
>
> > });
>
> > }
>
> > }
>
>
>
>
> What is wrong in my code ?
>
> So where should i put the method exavtly Sir ?
>
> ------------------------
> Raghu
>
>