This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
about setIconImage()
eLL Pascual
Greenhorn
Joined: May 22, 2008
Posts: 21
posted
Jun 04, 2008 21:18:00
0
How can I make setIconImage() work?
this is my source code:
code:
----------------------------------------------------------------------------
public notepad(){//constructor
...
...
loadFrameIcon();
}
private void loadFrameIcon(){
URL imgURL = null;
ImageIcon
imgIcon = null;
imgURL = notepad.class.getResource("images/notepadIcon.gif");
imgIcon = new
ImageIcon
(imgURL);
Image img = imgIcon.getImage();
this.setIconImage(img);
}
----------------------------------------------------------------------------
the error is:
cannot find symbol
this.setIconImage(img);
symbol: method setIconImage(
java.awt.Image
)
location: class notepad
Should I import something?
In the tutorial, the only import is .ImageIcon;
Thanks!
Norazanita Adnan
Ranch Hand
Joined: May 28, 2008
Posts: 44
posted
Jun 04, 2008 21:52:00
0
import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.text.*; import javax.swing.event.*; class FrameIconExample extends JFrame { privateJLabellabel1;//4 the label private ImageIcon imgeIcon1 = new ImageIcon();// 4 public FrameIconExample() { //setting for the title bar setTitle( "tyring........" ); setSize( 600, 450 ); setBackground( Color.cyan ); JPanel topPanel= new JPanel(); topPanel.setLayout(null ); getContentPane().add( topPanel ); BufferedImage imageIcon1 = null; try { imageIcon1 = ImageIO.read(new File("test1.jpg")); } catch (IOException e) { } JLabel xxx = new JLabel ( new ImageIcon (imageIcon1)); xxx.setBounds(200,50,260,250); xxx.setEnabled(true); topPanel.add (xxx); label1 = new JLabel( "PIC1:"); label1.setBounds( 100, 250, 50, 20 ); label1.setLabelFor( jlblImageViewer1 ); topPanel.add( label1 ); } public static void main(String[] args) { FrameIconExample frame = new FrameIconExample(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
hope this can help you...
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
I like...
posted
Jun 05, 2008 01:47:00
0
Originally posted by eLL Pascual:
How can I make setIconImage() work?
By either creating the method yourself, or have your class extend a class with the method like
JFrame
.
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions
How To Answer Questions
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: about setIconImage()
Similar Threads
Loading an Image
Refresh problem in applet
how to change the ImageIcon of a JLabel?
how to display an image for window icon in Swings
Icons and Images question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter