Questions tagged [imageicon]

An ImageIcon is an implementation of the Icon interface in Java Swing.

An ImageIcon is an implementation of the Icon interface in Java Swing. ImageIcon paints an icon from GIF, JPEG, or PNG files1 2 or a java.awt.Image.

  1. Sources for images might be constructed from
    • File (rarely useful)
    • String denoting the path to a File (N.B. often leads to the 'loading resource error mentioned below').
    • URL (typically used for )
    • Image
    • InputStream that is from/of an image.
  2. The image formats you can rely on the J2SE to handle is as above, JPG, PNG & GIF. OTOH Java based image I/O formats are provided by Service Provider Interface. Any particular JRE might support more formats.

Resources

FAQ

  1. What's an easy way to display an Image in Java/Scala?
  2. Loading Icon resource error
  3. How to turn ImageIcon to gray on Swing
  4. Use animated GIF in desktop application
  5. Getting label icon to appear above text
  6. Image Scaling
1040 questions
51
votes
2 answers

Java in Eclipse: Where do I put files on the filesystem that I want to load using getResource? (e.g. images for an ImageIcon)

I know the file needs to be where the getClass().getResource(filename) can find it, but I don't know where that is. I'm interested both in where to put the files on the filesystem itself, and how to go about using Eclipse's functionality to set up…
Andrew Larned
  • 923
  • 2
  • 8
  • 19
48
votes
5 answers

Java Swing: Displaying images from within a Jar

When running a Java app from eclipse my ImageIcon shows up just fine. But after creating a jar the path to the image obviously gets screwed up. Is there a way to extract an image from the jar at runtime so I can then open it up? Or, is there a…
jjnguy
  • 136,852
  • 53
  • 295
  • 323
33
votes
6 answers

Sizes of frame icons used in Swing

We can use a list to initialise the window icons using Window.setIconImages(List). What are the different sizes of icons typically used for in a JFrame? Code This code turns 64 different sized images (from 16x16, incrementing by 2)…
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
32
votes
2 answers

How to use image icon (from assets) instead of IconData and pagination bottomNavigationBar in Flutter

I am using bottomNavigationBar in my flutter project I'm new in flutter and have I no idea about pagination and use assets image icons instead of iconData. I searched about it for the last 2 days but not got satisfaction. Please help me...... I used…
user10522232
29
votes
3 answers

C# console application icon

Does anyone know how to set a C# console application's icon in the code (not using project properties in Visual Studio)?
pour toi
  • 1,026
  • 2
  • 13
  • 25
25
votes
5 answers

Convert BufferedImage to ImageIcon

How can I convert a BufferedImage to an ImageIcon? I can not find any documentation on this.
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
23
votes
7 answers

Scale the ImageIcon automatically to label size

On my JFrame, I am using the following code to display an image on the Panel : ImageIcon img= new ImageIcon("res.png"); jLabel.setIcon(img); I would like to "auto-size" the picture in the label. Indeed, sometimes the image size is only few…
martin8
  • 231
  • 1
  • 2
  • 3
18
votes
5 answers

Java - Convert Image to Icon/ImageIcon?

I have an Image object that I would like to convert to an Icon or ImageIcon to add to a JTextPane. How would I go about doing this? (this is in JAVA) clarification: my "Image" is an instance of the Image Object, not a File.
Primm
  • 1,347
  • 4
  • 19
  • 32
16
votes
11 answers

Java getClass().getResource("file") leads to NullPointerException

I am following the Snake Java games tutorial and always get this error: ImageIcon iid = new ImageIcon(this.getClass().getResource("ball.png")); ball = iid.getImage(); Exception in thread "main" java.lang.NullPointerException at…
kapitanluffy
  • 1,269
  • 7
  • 26
  • 54
14
votes
2 answers

Displaying an image in Java Swing

public class MinesweeperMenu extends MinesweeperPanel{ private JPanel picture = new JPanel(); private JButton play = new JButton("Play"); private JButton highScores = new JButton("High Score and \nStatistics"); private JButton changeMap = new…
Dominick Piganell
  • 704
  • 2
  • 10
  • 29
14
votes
6 answers

Setting the default application icon image in Java swing on OS X

I'm trying to set the icon image for a Jar file: setIconImage(new ImageIcon(getClass().getResource("logo.png")).getImage()); When running in Mac OS X 10.7.4 I get the following error: Jun 28 15:21:40 (my dhcp) java[73383] : CGContextGetCTM:…
rhombidodecahedron
  • 7,693
  • 11
  • 58
  • 91
14
votes
2 answers

Java: ImageIcon vs. Image difference

Could anyone explain to me in noob way what the difference is betweeen ImageIcon and Image classes/objects in Java? Thanks
ps-aux
  • 11,627
  • 25
  • 81
  • 128
12
votes
3 answers

Remove icon from JOptionPane

How to remove icon from JOptionPane? ImageIcon icon = new ImageIcon(image); JLabel label = new JLabel(icon); int result = JOptionPane.showConfirmDialog((Component) null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION);
Code Hungry
  • 3,930
  • 22
  • 67
  • 95
12
votes
3 answers

Converting an ImageIcon to a BufferedImage

I've been trying to convert a ImageIcon to BufferedImage... And I've had no luck. I have a pre-existing ImageIcon that needs to be converted to a Buffered Image for the vast amount of BufferedImage operations that exist. I have found a few ways, but…
Caelum
  • 801
  • 2
  • 10
  • 19
11
votes
4 answers

How to change the brightness of an Image

My Question: I want to be able to change the brightness of a resource image and have three instances of it as ImageIcons. One at 50% brightness (so darker), another at 75% brightness (a little brighter), and finally another at 100% brightness (the…
kentcdodds
  • 27,113
  • 32
  • 108
  • 187
1
2 3
69 70