Results 1 to 20 of 20
  1. #1
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Netbeans 6.5, Java and icons differences

    :confused:

    I have put a JFrame together using textpad that has an icon in it replacing the java cup, now I want to use it in netbeans but for some reason it does not like the code.

    The code in the .java file is

    Java Code:
    // start of icon code for frame icon
    
    	     	Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
    	     	Label lblicon = new Label("",Label.LEFT);
    	     	frame.add(lblicon);
    	     	frame.setIconImage(icon);
    
    	  // end of icon code

    The code I have put into Netbeans is

    Java Code:
    // start of icon code for frame icon
    
    	     	Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
    	     	Label lblicon = new Label("",Label.LEFT);
    	     	jPanel1.add(lblicon);
    	     	jPanel1.setIconImage(icon);
    
    	  // end of icon code
    The error I get is cannot find symbol

    I thought this was in the import java.awt.Image;?

    I also get in the same error message

    Java Code:
    method.setIconImage(java.awt.Image)
    and finally

    Java Code:
    Location:class javax.swing.JPanel
    What am I missing.

    Thanks in advance.

  2. #2
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    I have read and tried the posts at

    How to change Window Icon

    But still have not managed to get it working.

    Thanks in advance

    :confused:

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default

    It might be easier if you post the actual (and complete) compiler message as these things are very useful.

    But notice that JPanel does not have a setIconImage() method. (which makes sense because the icon image is an icon image of a frame) So you can't really say "jPanel1.setIconImage(icon);".

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default

    Quote Originally Posted by dbashby View Post
    I have read and tried the posts at

    How to change Window Icon

    But still have not managed to get it working.

    Thanks in advance

    :confused:
    Notice how in the example that the Captain(*) posted sets the icon image for a frame.

    If you can't "get it working" post saying what "working" means: compiler message? runtime exception? strange runtime behaviour (like no icon appearing)? Actual code and full messages/output are good.

    (*) Has anyone heard of Captain Morgan recently?

  5. #5
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    OK the image is off the working java file written in textpad, as you see the icon has changed, this is what I am looking to do in netbeans apart from a dif image for the icon.

    in that file the icon code is

    Java Code:
    // start of icon code for frame icon
    
    	     	Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
    	     	Label lblicon = new Label("",Label.LEFT);
    	     	frame.add(lblicon);
    	     	frame.setIconImage(icon);
    
    	  // end of icon code
    This wont work in netbeans so after adjustments I ended with

    Java Code:
    /*    // start of icon code for frame icon
    
    	     	Image icon = Toolkit.getDefaultToolkit().getImage("icon.ico");
    	     	Label lblicon = new Label("",Label.LEFT);
    	     	jPanel1.add(lblicon);
    	     	jPanel1.setIconImage(icon);
    
    	  // end of icon code */
    No the icon is not there

    The error messages etc are referring to the

    Java Code:
    setIconImage
    Java Code:
    Cannot find symbol
              Symbol:Method setIconImage(java.awt.Image)
              location : class javax.swing.JPanel
    That is the complete error message word for word

    Also Netbeans uses JPanels so how do i get round this.

    Google has loads of links but not 1 has solved the problem for me so far and so I am hoping someone has come accross this b4 and resolved the issue.


    Thanks in advance

  6. #6
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    The error message I get in the output panel is

    Java Code:
    init:
    deps-clean:
    Deleting directory C:\Users\david\Documents\NetBeansProjects\BubbleSortArray\BubbleSortArray\build
    Deleting directory C:\Users\david\Documents\NetBeansProjects\BubbleSortArray\BubbleSortArray\dist
    clean:
    init:
    deps-jar:
    Created dir: C:\Users\david\Documents\NetBeansProjects\BubbleSortArray\BubbleSortArray\build\classes
    Compiling 6 source files to C:\Users\david\Documents\NetBeansProjects\BubbleSortArray\BubbleSortArray\build\classes
    C:\Users\david\Documents\NetBeansProjects\BubbleSortArray\BubbleSortArray\src\bubblesortarray\BubbleSort.java:56: cannot find symbol
    symbol  : method setIconImage(java.awt.Image)
    location: class javax.swing.JPanel
                         jPanel1.setIconImage(icon);
                                ^
    Note: C:\Users\david\Documents\NetBeansProjects\BubbleSortArray\BubbleSortArray\src\bubblesortarray\Main.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    1 error
    BUILD FAILED (total time: 1 second)
    Everything works fine if i take the icon code out so it is definately that

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default

    Also Netbeans uses JPanels so how do i get round this.

    The problem is as I said before: you are calling a non-existent method. There is no setIconImage() for a panel. An icon image is an icon image for a frame.

    I'm not all that familiar with NB, perhaps someone else can say how you would go about getting a reference to the frame. But that's what you need. Get a reference to the frame and call the frame's setIconImage() method.

  8. #8
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    Thanks, I did read what you said regarding the setIconImage but I am unaware of the answer hence me being here.

    I would appreciate some assistance

    Thanks in advance

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  10. #10
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    Well ok lets just say I do not understand the answer then for the sake of argument, could you elaborate please.

    Thanks in advance:confused:

  11. #11
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default Netbeans generated code

    This is what netbeans generated

    Java Code:
    private javax.swing.ButtonGroup buttonGroup1;
        private javax.swing.JButton cmdExit;
        private javax.swing.JButton cmdHelp;
        private javax.swing.JButton cmdReset;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JLabel lblIcon;
        private javax.swing.JLabel lblSentence;
        private javax.swing.JOptionPane optPane1;
        private javax.swing.JRadioButton rbtnAscendBmiReading;
        private javax.swing.JRadioButton rbtnAscendMbrNum;
        private javax.swing.JRadioButton rbtnLargestBmiReading;
        private javax.swing.JRadioButton rbtnMbrPar;
        private javax.swing.JRadioButton rbtnSmallestBmi;
        private javax.swing.JTextField txtEightA;
        private javax.swing.JTextField txtEightB;
        private javax.swing.JTextField txtEighteenA;
        private javax.swing.JTextField txtEighteenB;
        private javax.swing.JTextField txtElevenA;
        private javax.swing.JTextField txtElevenB;
        private javax.swing.JTextField txtFifteenA;
        private javax.swing.JTextField txtFifteenB;
        private javax.swing.JTextField txtFiveA;
        private javax.swing.JTextField txtFiveB;
        private javax.swing.JTextField txtFourA;
        private javax.swing.JTextField txtFourB;
        private javax.swing.JTextField txtFourteenA;
        private javax.swing.JTextField txtFourteenB;
        private javax.swing.JTextField txtMessage;
        private javax.swing.JTextField txtNineA;
        private javax.swing.JTextField txtNineB;
        private javax.swing.JTextField txtNineteenA;
        private javax.swing.JTextField txtNineteenB;
        private javax.swing.JTextField txtOneA;
        private javax.swing.JTextField txtOneB;
        private javax.swing.JTextField txtSevenA;
        private javax.swing.JTextField txtSevenB;
        private javax.swing.JTextField txtSeventeenA;
        private javax.swing.JTextField txtSeventeenB;
        private javax.swing.JTextField txtSixA;
        private javax.swing.JTextField txtSixB;
        private javax.swing.JTextField txtSixteenA;
        private javax.swing.JTextField txtSixteenB;
        private javax.swing.JTextField txtTenA;
        private javax.swing.JTextField txtTenB;
        private javax.swing.JTextField txtThirteenA;
        private javax.swing.JTextField txtThirteenB;
        private javax.swing.JTextField txtThreeA;
        private javax.swing.JTextField txtThreeB;
        private javax.swing.JTextField txtTwelveA;
        private javax.swing.JTextField txtTwelveB;
        private javax.swing.JTextField txtTwentyA;
        private javax.swing.JTextField txtTwentyB;
        private javax.swing.JTextField txtTwoA;
        private javax.swing.JTextField txtTwoB;

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Do you understand what he means about getting the reference to the JFrame?
    Last edited by Fubarable; 10-10-2009 at 06:20 AM.

  13. #13
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    With the greatest respect Fubarable if i knew the answer I would not be here.

    As someone who has java as a small part of a course the environment of netbeans is where I am at, so if someone can assist in answering the question in a way i can understand I would be grateful with a little less superiority.

    Thanks in advance

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm sorry, I"m not meaning to act superior, as I am certainly not superior to you or anyone. I do have biases about NetBeans code generation as most of us find it difficult to answer Swing questions from users of this product as it shields the user from complexity but also shields them from needing to learn the underpinnings of Swing.

    I do need to know though do you understand what he meant about getting the reference to the JFrame. If you do understand that, you can likely solve this easily, but if you don't, then you need to understand this concept before you can move forward. If you can find a way of getting a reference to this JFrame, then you can call the method that you're already familiar with, as simple as that. If you understand this, then we can work on getting this reference and dealing with it.

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Another solution to help get the best of both worlds: if you know how to add an icon to a JFrame outside of NetBeans, but still are stuck with using NetBeans code generation due to time constraints, then use NetBeans to create your GUI in a JPanel, not a JFrame. Then you can create your own JFrame in whatever text editor you like, add the icon to it, and then use the NetBeans' generated JPanel as this JFrame's contentPane.

  16. #16
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    The problem I have is that the java element of my course is 100% aimed at netbeans, the time spent in this particular class is aimed at thinking like a programmer rather than learning java, java is the vehicle they are using to make us think like a programmer so they spend no time in actually teaching the java syntax.

    In answer to your question

    I think I do but I am not sure, the referance to the JPanel and JFrame is calling and adding that particular element.......is this correct?

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    A non-primitive variable holds a reference to an object, and what we need is a reference to your main JFrame. One thing I forgot to ask is, does your main class subclass anything? Does it subclass JFrame, for instance?

  18. #18
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    In snaswer to
    does your main class subclass anything?
    For the frame no, but it does call on other classes for other things that are not tied to the gui.

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Where does the code initialize the JFrame itself? What does this code look like? do you have a JFrame variable here?

  20. #20
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    The code that netbeans generates initializes the JFrame, for the moment I will assume you have not used netbeans at least for a long time, basically as with other software it is wysiwyg, there is a swing menu that you drag and drop components, the main frame is already there when you start a project whether it be an applet or application.

Similar Threads

  1. J2EE and J2ME differences
    By ianbram in forum Advanced Java
    Replies: 3
    Last Post: 11-27-2008, 10:19 AM
  2. Replies: 3
    Last Post: 07-23-2008, 09:07 AM
  3. Differences between constructor and method
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-19-2007, 09:53 AM
  4. differences: AWT and Swing
    By baltimore in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 10:01 AM
  5. differences between 2 dates
    By cecily in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 06:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •