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
10
votes
5 answers

How to change java icon in a JFrame

Ok so I've been researching this one quiet a bit. I am fairly new to java but thought that this one would be easy. Ive tried just about every way that has been answered on this site and still no luck, and usually when I look here I am able to find a…
Garrett Shaw
  • 103
  • 1
  • 1
  • 6
10
votes
5 answers

Null pointer exception when an ImageIcon is added to jbutton in NetBeans

An ImageIcon is added to button properties using NetBeans. print.setFont(new java.awt.Font("Serif", 0, 14)); print.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project/print.gif"))); print.setMnemonic('P'); …
VenuMadhava
  • 103
  • 1
  • 1
  • 6
9
votes
3 answers

What causes poor image quality in Java JLabel icons?

Java JLabel icons are displaying with distorted pixels in JFrame. This is happening consistently with different png images (all 32x32). I am not scaling the images, they are displayed in the program 32x32, which I verified using getWidth and…
IamJohnGalt
  • 93
  • 1
  • 6
9
votes
3 answers

Customize JOptionPane Dialog

I am learning java swing. The code below is a catch block which handles an IOException and shows a error message. catch(IOException e) { System.out.println("IOException"); JOptionPane.showMessageDialog(null,"File not…
Victor Mukherjee
  • 10,487
  • 16
  • 54
  • 97
8
votes
3 answers

Auto-resizing JButton Icon

so I have this JButtons to which I add Icons. The Icons are too large initially, so I resize them beforehand, and it works fine. Except that when I resize the window, the JButtons change size, but not the Icons, which is problematic. Is there a way…
Cristol.GdM
  • 505
  • 2
  • 5
  • 21
8
votes
1 answer

Changing Desktop Icon for Java Application

I wish to thank you in advance for taking the time to read my question, and I would greatly appreciate any comments, answers, insights, techniques and critiques that you may be able to provide. I'm looking for a useful method for changing the…
Jeremy Johnson
  • 469
  • 1
  • 4
  • 17
8
votes
3 answers

Java Swing ImageIcon, where to put images?

I'm following this tutorial for java swing games: http://zetcode.com/tutorials/javagamestutorial/movingsprites/ At this point: ImageIcon ii = new ImageIcon(this.getClass().getResource()); image = ii.getImage(); I just don't know what kind of path I…
Dren Skywalker
  • 129
  • 1
  • 2
  • 10
8
votes
5 answers

How to set Icon to a JLabel from an image from a folder?

I am trying to set an icon to a JLabel from a folder of images whenever an item is selected from a JComboBox. The name of items in the JComboBox and name of the images in the folder are same. So whenever an item is selected from the JComboBox, the…
Raed Shahid
  • 241
  • 5
  • 7
  • 12
8
votes
3 answers

How to add an ImageIcon to a JFrame?

I'm trying to add an image to one frame but it seems it does not working. The image created by an ImageIcon from the specified file. The image file is in the seam directory the java file exist. import java.awt.BorderLayout; import…
Bernard
  • 4,240
  • 18
  • 55
  • 88
8
votes
3 answers

Java adding ImageIcon to JLabel

I am trying to make a very basic game with Java and I am having trouble displaying an image on a JFrame. It has worked in the past for me and now is not, i can't see what I did wrong. I have tried printing the current working directory and changing…
user1486826
  • 119
  • 1
  • 1
  • 8
7
votes
6 answers

Creating custom JButton from images containing transparent pixels

Read edit 2 for what I'm actually missing to make it work I'm currently trying to create some custom JButtons using images created in photoshop that have an alpha parameter. So far, overriding the paint() method to draw the image has worked in the…
Jumbala
  • 4,764
  • 9
  • 45
  • 65
7
votes
5 answers

Difference between Icon and ImageIcon?

Icon bug = new ImageIcon( getClass().getResource( "bug1.png" ) ); ImageIcon bug = new ImageIcon( getClass().getResource( "bug1.png" ) ); What's the difference between these two? My book always uses the way in the first line to declare an ImageIcon…
stumped
  • 3,235
  • 7
  • 43
  • 76
7
votes
5 answers

How to make drawn images transparent in Java

I got the animation to work in my Snake Clone Game. But the problem based on the picture is that the images do not have transparency(notice the white background of the circle pictures. Programming-wise, is there a fix to be able to include…
Nicholas
  • 679
  • 2
  • 11
  • 29
7
votes
1 answer

JLabel mouse click on icon or text

When it is clicked on JLabel, I want to understand if the click was on "Icon part", or "Text part" of the JLabel, so that different action can be taken. Is there a clever way to do that? Or just I have to solve it relatively with the coordinates of…
Mert Mertce
  • 1,614
  • 3
  • 21
  • 32
7
votes
2 answers

JLabel images array

I am trying to load the same jlabel stored image twice into a gridlayout panel, however instead of creating two instances of the image, the image is only displayed once then moved. How can I store the same JLabel position in the pieces array into…
user1334130
  • 1,131
  • 3
  • 18
  • 25
1
2
3
69 70