How can I change the default icon of JFrame (java cup) to my desired image in netbeans

View: New views
7 Messages — Rating Filter:   Alert me  

How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by ankitraghu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please Answer .[/b][/i]

------------------------
Raghu





Re: How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by Tonny Kohar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

On Wed, Oct 28, 2009 at 6:51 PM, ankitraghu <ankitraghu@...> wrote:
> Please Answer .[/b][/i]
>

myFrame.setIconImage(Image theImage);


Cheers
Tonny Kohar
--
Sketsa SVG Editor
imagine, design, create ...
http://www.kiyut.com

How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by ankitraghu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tonny,



It doesn't works , error occured . I have imported :-

import java.awt.Image;

import javax.swing.JFrame;



Error Occurred :



Cannot find symbol

Symbol: Class setIconImage

location : Class javax.swing.JFrame



<identifier >expected

------------------------
Raghu





How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by bhobiger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you post your code? It looks like you put your call in the wrong place.





How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by ankitraghu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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





RE: How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by John C. Turnbull :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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



How can I change the default icon of JFrame (java cup) to my desired image in netbeans

by ankitraghu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you for helping me as well giving so important explanation.



This explanation works great !



Can i have ur email id Please for further queries, i think u can help me allot in learning Java .

------------------------
Raghu