Results 1 to 20 of 20
- 10-10-2009, 01:06 AM #1
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
The error I get is cannot find symbolJava 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
I thought this was in the import java.awt.Image;?
I also get in the same error message
and finallyJava Code:method.setIconImage(java.awt.Image)
What am I missing.Java Code:Location:class javax.swing.JPanel
Thanks in advance.
- 10-10-2009, 01:56 AM #2
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:
- 10-10-2009, 01:57 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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);".
- 10-10-2009, 02:01 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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?
- 10-10-2009, 03:16 AM #5
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
This wont work in netbeans so after adjustments I ended withJava 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
No the icon is not thereJava 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 */
The error messages etc are referring to the
Java Code:setIconImage
That is the complete error message word for wordJava Code:Cannot find symbol Symbol:Method setIconImage(java.awt.Image) location : class javax.swing.JPanel
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
- 10-10-2009, 03:20 AM #6
The error message I get in the output panel is
Everything works fine if i take the icon code out so it is definately thatJava 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)
- 10-10-2009, 04:04 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 10-10-2009, 04:32 AM #8
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
-
- 10-10-2009, 04:53 AM #10
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:
- 10-10-2009, 04:56 AM #11
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;
-
Do you understand what he means about getting the reference to the JFrame?
Last edited by Fubarable; 10-10-2009 at 05:20 AM.
- 10-10-2009, 03:06 PM #13
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
-
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.
-
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.
- 10-10-2009, 03:34 PM #16
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?
-
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?
- 10-10-2009, 03:54 PM #18
In snaswer to
For the frame no, but it does call on other classes for other things that are not tied to the gui.does your main class subclass anything?
-
Where does the code initialize the JFrame itself? What does this code look like? do you have a JFrame variable here?
- 10-10-2009, 04:27 PM #20
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
-
J2EE and J2ME differences
By ianbram in forum Advanced JavaReplies: 3Last Post: 11-27-2008, 09:19 AM -
What're the differences between JSP, Java Script, and Java Applet?
By meili100 in forum New To JavaReplies: 3Last Post: 07-23-2008, 08:07 AM -
Differences between constructor and method
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 08:53 AM -
differences: AWT and Swing
By baltimore in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 09:01 AM -
differences between 2 dates
By cecily in forum New To JavaReplies: 1Last Post: 08-02-2007, 05:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks