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
7
votes
1 answer

Is there an alternative to getClass().getResource() for a Static ImageIcon

Ok so I got a static ImageIcon and the Image just doesn't show up. In the same program I use other ImagesIcon but they are not static so when I declare them I do it like this: public ImageIcon blabla = new…
Alex
  • 865
  • 13
  • 24
6
votes
4 answers

Java - Draw text in the center of an image

I need to write text in the center of an image. The text to write is not always the same. The code I'm using is here: // Here I first draw the image g.drawImage(img, 22, 15, 280, 225, null); // I get the text String text = photoText.getText(); //…
GhzNcl
  • 149
  • 1
  • 4
  • 13
6
votes
1 answer

How to add image in jlist

Hi i have created a j list and there i want to add an image before any text in that text how can i do this i tried but i am not able to achieve my goal i want to add an image before list element"Barmer". public class ListDemo extends JPanel …
user3377703
6
votes
3 answers

save resized image java

How do i save a resized image to a specific folder? private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { ImgChooser ic = new ImgChooser(); ImageIcon icon = new ImageIcon(me,"id…
Weddy
  • 543
  • 6
  • 10
  • 21
6
votes
2 answers

Which Image to Use

I've read the java api, but I still do not understand the main difference between: 1) ImageIcon 2) BufferedImage 3) VolatileImage 4) Image Can someone tell me when each one is used?
Anonymous181
  • 1,863
  • 6
  • 24
  • 27
5
votes
3 answers

Overlay a JButton over JLabel in Java Swing?

Is it possible to overlay a Button over a Label in Swing? For example, if have a JLabel with image and no text, and i want to overlay my button over this JLabel. Label is defined something like: myLabel = new javax.swing.JLabel(new ImageIcon(…
Johnydep
  • 6,027
  • 20
  • 57
  • 74
5
votes
4 answers

Resizing an image in swing

I have snippet of code that I am using for the purpose of resizing an image to a curtain size (I want to change the resolution to something like 200 dpi). Basically the reason I need it is because I want to display the image that the user have…
Paul Kar.
  • 1,293
  • 2
  • 21
  • 32
5
votes
1 answer

Can we create our own custom icons with Font Awesome?

i have web application, i want to use different icons in my project for that i have used following css and code.

fa-camera-retro

fa-camera-retro

Mitul Maheshwari
  • 2,647
  • 4
  • 24
  • 38
5
votes
1 answer

JLabel get Image

Is there any better way to get the Icon of a JLabel in a container as a BufferedImage whithout multiple casts? Component[] components = container.getComponents(); BufferedImage image = ((BufferedImage) ((ImageIcon) ((JLabel)…
Sp0tlight
  • 409
  • 1
  • 4
  • 18
5
votes
3 answers

JButton background image

Hi i am trying to implement Action listener for JButton and code look like following: ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png")); one = new JButton("",imageForOne); one.setPreferredSize( new Dimension(78,…
usrNotFound
  • 2,680
  • 3
  • 25
  • 41
5
votes
6 answers

What is the correct path to display an ImageIcon png file for Windows 7?

I wanted to test having a program with a simple png image on it. I wrote a short program that does this, but I can't seem to get the path right. I have checked, checked again, rechecked, and quadruple checked my path name as to not get it right, but…
user2398233
  • 137
  • 1
  • 2
  • 10
5
votes
2 answers

Align text and icon differently in JLabel

i'm trying to create a JLabel that has text aligned left and icon aligned right, i tried this code: _ip = new JLabel(ip); _ip.setFont(boldFont); _ip.setBounds(5, 0, 100,…
BackSlash
  • 21,927
  • 22
  • 96
  • 136
5
votes
5 answers

I want a picture to stay in top left corner of a jscrollpane while scrolling

I have a JPanel in a JScrollpane. I draw on a BufferedImage, which I display on the JPanel. In the top left corner of the JScrollpane, I want a picture, that always stays in that corner when I scroll down to see the rest of my JPanel. Here the…
5
votes
3 answers

getResources() for ImageIcon - java

my very first question: I've been trying to figure this out for a couple of days, but I got to the point I lost my patience. The following are some code and my project structure. QUESTION: how can I get getResources() to work in eclipse and after…
Fer
  • 460
  • 2
  • 4
  • 17
5
votes
2 answers

The method about ImageIcons does not work

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Cards extends JFrame { private GridLayout grid1; JButton []bt=new JButton[52]; ImageIcon tail=new ImageIcon(getClass().getResource("b1fv.png")); …
Yuhan Su
  • 59
  • 5
1 2
3
69 70